T
Two-Horned Unicorn
The following code compiles and works as expected when
compiled with gcc.
/* empty-args.c */
#include <stdio.h>
#define foo(x,y) puts("bar: x=\"" #x "\"; y=\"" #y "\"")
#define bar(x) puts("foo: x=\"" #x "\"")
int main(void)
{
foo(,);
foo(FOO,);
foo(,BAR);
foo(FOO,BAR);
bar();
bar(FOO);
return 0;
}
However, when I compiled it with a different compiler, I received
the following compiler messages:
| cpp: empty-args.c:14 Disagreement in number of macro arguments
| Warning empty-args.c: 14 missing prototype for bar
| Warning empty-args.c: 14 Missing prototype for 'bar'
| 0 errors, 3 warnings
| empty-args.obj .text: undefined reference to '_bar'
| linker returned 1
It seems there are no problems with 'foo' if one or both arguments
are empty, but the same is not true for 'bar'. Is this an extension
in gcc? A new thing in C99?
What does the standard say? (I'm not that good at standardese)
compiled with gcc.
/* empty-args.c */
#include <stdio.h>
#define foo(x,y) puts("bar: x=\"" #x "\"; y=\"" #y "\"")
#define bar(x) puts("foo: x=\"" #x "\"")
int main(void)
{
foo(,);
foo(FOO,);
foo(,BAR);
foo(FOO,BAR);
bar();
bar(FOO);
return 0;
}
However, when I compiled it with a different compiler, I received
the following compiler messages:
| cpp: empty-args.c:14 Disagreement in number of macro arguments
| Warning empty-args.c: 14 missing prototype for bar
| Warning empty-args.c: 14 Missing prototype for 'bar'
| 0 errors, 3 warnings
| empty-args.obj .text: undefined reference to '_bar'
| linker returned 1
It seems there are no problems with 'foo' if one or both arguments
are empty, but the same is not true for 'bar'. Is this an extension
in gcc? A new thing in C99?
What does the standard say? (I'm not that good at standardese)