Talk:C Programming/Preprocessor directives and macros

side effects
It seems that an small has appeared int the #define paragraph : int x = -10; int j = ABSOLUTE_VALUE( x++ );
 * 1) define ABSOLUTE_VALUE( x ) ( ((x) < 0) ? -(x) : (x) )

--> x = -8 and not -7 as said, because althought the x++ is expanded 3 times, it is executed only 2 in the flow.

Calculated Includes and X-Macros
I asked this on the wikipedia discussion page and it was suggested that it be brought up here.

There is no explanation of this in this page, and what are some real world examples of how to use it - instead of the simple: Is it possible to combine X-Macro capabilities with calculated includes? How would you do it?


 * I am surprised to learn that "calculated includes" are even possible.
 * Based on my reading of "Include Syntax", I was under the impression that "calculated includes" are not possible, since the documentation seems to say that macro names in the argument of the "#include" statement are not expanded.
 * However, I did a quick test and it seems that they are expanded; the compiler I'm using today does include a file whose actual name is set in a previous "#define" statement.
 * I've never seen "calculated includes" before. As far as I know there are no real-world examples of "calculated includes", but I would be surprised and delighted to learn something new. --DavidCary (discuss • contribs) 23:44, 13 August 2015 (UTC)

#define for autoincrementing variables
I am missing the preprocessor possibility, how to automaticly generate variables with incrementing "index", i.e. Var1, Var2, Var3, ... incrementing for every appearence of a special preprocessor directive. Finally the highest index can be used by a further directive. -- 91.96.72.228 (talk) 14:17, 27 February 2009 (UTC)


 * I'm not sure that's very relevant to this book. There's no built-in way to do what you ask, although __LINE__ combined with token pasting (##) can be used to get a similar effect in many cases.  If the book doesn't mention __LINE__ and __FILE__, it should. -- James Dennett (talk) 19:55, 28 February 2009 (UTC)


 * I hear that one can use the  macro to get an incrementing index in most popular compilers.
 * Some more details, and other approaches to incrementing or decrementing in the preprocessor:
 * "Use the c preprocessor to increment defines?"
 * "How can I generate unique values in the C preprocessor?"
 * "99 Bottles of Beer using the C Preprocessor"


 * However, most people -- including myself -- have never used the  symbol or other "preprocessor-incremented variable names".
 * See "Has anyone ever had a use for the __COUNTER__ pre-processor macro?"
 * It always seems that some other approach -- such as using __LINE__ and __FILE__, or using an array Var[1], Var[2], Var[3], or perhaps creating new variables at run-time with calloc (rather than at preprocessor time), etc. -- always ends up more generally useful. Perhaps the same will also be true in your case. --DavidCary (discuss • contribs) 03:04, 21 May 2011 (UTC)

preprocessor is a part of the compiler (?)
I think the wording here is a bit ambiguous: "The preprocessor is a part of the compiler which performs preliminary operations (conditionally compiling code, including files etc...) to your code before the compiler sees it." "Directives are handled by the preprocessor, which is either a separate program invoked by the compiler or part of the compiler itself."

Variadic Macros
Variadic Macros are missing. They are similar to variadic functions and are in the ISO standard since C99. See http://en.wikipedia.org/wiki/Variadic_macro

Simpler examples please
Examples in X macros, or example, should only focus in what an X macro is. My suggestion is: can be written with macros: may be generalized to Another generalization passing macro name Just fill with the explanation, it is based in the wikipedia article, explain why variadic macros are convenient. Test the macros and correct mistakes if any. And that's all to make it more simple. Not distract with complex examples. Other examples can be simplified too.