Is it possible to put several #define
preprocessor commands together in C?
For example, instead of this:
#define a 1
#define b 2
#define c 3 ...
just this:
#define a1, b2, c3
No, the preprocessor phase is just text replacement and meant to be simple to parse. Therefore all preprocessor directives
#
in particular a macro definition via #define
extends until the end of the line and the preprocessing phase wouldn't be able to decide that you intend to declare multiple macros in one go. In the syntax that you propose the content of the macro a
would in fact be , b2, c3
which is probably not what you want :)
No. According to the latest C99 standard, http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf page 146, as well as the current C11 standard, http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf page 161, the syntax of a control-line beginning with #define
has only one identifier (not counting function-like arguments in an identifier-list) and one replacement-list before the new-line character.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With