From d7af004437debe21ca473eefa4c1d09d1ae4e043 Mon Sep 17 00:00:00 2001 From: Richard Stallman Date: Sun, 18 Sep 2022 20:45:22 -0400 Subject: [PATCH] (Function-like Macros): Explain whitespace around `(' is ok in macro calls. (Variadic Macros): Delete spurious `;' in some expansion examples. --- cpp.texi | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cpp.texi b/cpp.texi index b19bc62..7e71ed1 100644 --- a/cpp.texi +++ b/cpp.texi @@ -752,11 +752,22 @@ These are called @dfn{function-like macros}. To define one, use the the macro name. For example, @example -#define lang_init() c_init() +#define lang_init() c_init () +lang_init () + @expansion{} c_init () +lang_init () + @expansion{} c_init () lang_init() - @expansion{} c_init() + @expansion{} c_init () @end example +There must be no space between the macro name and the following +open-parenthesis in the the @code{#define} directive; that's what +indicates you're defining a function-like macro. However, you can add +unnecessary spaces around the open-parenthesis (and around the +close-parenthesis) when you @emph{call} the macro; they don't change +anything. + A function-like macro is expanded only when its name appears with a pair of parentheses after it. If you write just the name, without parentheses, it is left alone. This can be useful when you have a @@ -1171,7 +1182,7 @@ an extra comma in the expansion: @example eprintf ("success!\n") - @expansion{} fprintf(stderr, "success!\n", ); + @expansion{} fprintf(stderr, "success!\n", ) @end example @noindent @@ -1192,7 +1203,7 @@ then use the macro @code{eprintf} with empty variable arguments, @example eprintf ("success!\n") - @expansion{} fprintf(stderr, "success!\n"); + @expansion{} fprintf(stderr, "success!\n") @end example @noindent