We just need to expand the macro. You can use gcc -E
to call only the preprocessor; it will also expand all #include
directives, so the output will be ugly.
But do it manually. Macro arguments are sequences of tokens, not expressions.
Macro Definition:
# define _2a(list,a1,a2) list a1;a2;
and the call:
main _2a((argc,argv), int argc, char * argv[]) { ... }
Arguments:
list
β (argc,argv)
a1
β int argc
a2
β char * argv[]
Making replacements gives us:
main (argc,argv) int argc; char * argv[]; { ... }
This is most often written on several lines:
main(argc, argv) int argc; char *argv[]; { ... }
This ad features an old style. It is still legal in all versions of C (right up to the 2011 standard), but it has been officially deprecated since 1989. The disadvantage of this old form is that it did not pass parameter information to the caller, so the compiler could not warn you if you called a function with the wrong number of argument types.
I would argue with an alternative definition of the _a2
macro, which is expanding to a more modern definition that includes a prototype, something like:
#define _2a(list,a1,a2) (a1, a2)
With this macro definition, the definition of main
extends to this instead:
main (int argc, char * argv[]) { ... }
So, the _a2
macro ("a" presumably means "argument") allows you to write code that can expand to either define an old-style style (for compilers to ANSI), or for a modern definition using a prototype.
A reasonable way to implement this would be:
#ifdef __STDC__ #define _2a(list,a1,a2) (a1, a2) #else #define _2a(list,a1,a2) list a1;a2; #endif
But since you are unlikely to find a C compiler that does not support prototypes (they have been a standard feature of the language for a quarter of a century), it would be wiser to just delete the macro and just use function declarations and style definitions.
In addition, there is no int
return type in the definition of main
. Prior to standard C 1999, it was legal to omit the return type in accordance with the "implicit int
" rule. The 1999 standard rejected this rule and made an explicit return type mandatory. Most C compilers in default mode still allow you to exclude the return type, possibly with a warning, but there is no reason to skip it.