I don't think there is anything in the standard that says you can't #define before #include'ing.hgm wrote:OK, thanks everyone. That clears up the mystery. It is bad to use identifiers that could be macros as formal parameters in function definitions in a header file, but I guess this can be excused by the directive that header files should be #included before any #defines. (Although this is a strange directive, as it is quite common to define macros through a compiler flag, like -DX, and then what??)
test.c:But that it does not give the error message on the line where it occurs is truly appalling.
Code: Select all
#define X 36
#include "test.h"
Code: Select all
int triple(int X)
{
return 3*X;
}
Code: Select all
$ gcc -c test.c
test.c:1:11: error: expected ‘;’, ‘,’ or ‘)’ before numeric constant
#define X 36
^
test.h:1:16: note: in expansion of macro ‘X’
int triple(int X)
^
Apparently the system headers include a directive that turns off diagnostic messages. That is fine if they are flawless, but confusing when they are not.
(*) The ';' confuses me, though. But "int triple(int ; )" in fact does compile without error... How is that legal C?
edit: System Headers (still, warnings are not errors)