We just have to expand the macro. You can use gcc -E
to invoke just the preprocessor; it will also expand all #include
directives, so the output is going to be ugly.
But let's do it manually. The arguments to the macro are token sequences, not expressions.
The macro definition is:
# define _2a(list,a1,a2) list a1;a2;
and the invocation is:
main _2a((argc,argv), int argc, char * argv[])
{
...
}
The arguments are:
list
--> (argc,argv)
a1
--> int argc
a2
--> char * argv[]
Performing the replacements gives us:
main (argc,argv) int argc; char * argv[];
{
...
}
This would more commonly be written on multiple lines:
main(argc, argv)
int argc;
char *argv[];
{
...
}
This is an old-style function declaration. It's still legal in all versions of C (up to and including the 2011 standard), but it's been officially obsolescent since 1989. The disadvantage of this old form is that it didn't communicate parameter information to callers, so a compiler couldn't warn you if you called a function with the wrong number of types of arguments.
I'll bet there's an alternate definition of the _a2
macro that expands to more modern definition that includes a prototype, something like:
#define _2a(list,a1,a2) (a1, a2)
With that macro definition, the definition of main
instead expands to this:
main (int argc, char * argv[])
{
...
}
So the _a2
macro (the "a" presumably stands for "argument") lets you write code that can expand either to an old-style function definition (for pre-ANSI compilers) or to a modern definition with a prototype.
A reasonable way to implement it would have been:
#ifdef __STDC__
#define _2a(list,a1,a2) (a1, a2)
#else
#define _2a(list,a1,a2) list a1;a2;
#endif
But since you're very unlikely to find a C compiler that doesn't support prototypes (they've been a standard feature of the language for a quarter of a century now), it would make more sense just to remove the macro altogether and just use modern style function declarations and definitions.
Also, the definition of main
is missing the return type of int
. Prior to the 1999 C standard, it was legal to omit the return type, under the "implicit int
" rule. The 1999 standard dropped this rule and made an explicit return type mandatory. Most C compilers in their default mode still permit the return type to be omitted, perhaps with a warning, but there's no good reason to omit it.
_2a
is most likely a macro, defined in some header file. – Docia_2a
is a macro. – Apatite