conditional compile...



hello all,

i wrote the small program below to practice conditional compiling. if i define MYSYMBOL then everthing works fine, but when i comment MYSYMBOL gcc gives the following message:
cnd_compile01.c:4:2: error: #error "Error"
cnd_compile01.c:1: warning: ISO C forbids an empty source file

i cant understand the warning and how to eliminate it? i tried placing some dummy comment but still the same warning.

also why is compiler printing error twice. it looks ugly. is there a way to make it print error once only?

thanks.

code:
/* #define MYSYMBOL 1 */

#if MYSYMBOL != 1
#error "Error"
#else

#include <stdio.h>
main() { puts("hello"); }

#endif
.



Relevant Pages

  • Re: conditional compile...
    ... i wrote the small program below to practice conditional compiling. ... define MYSYMBOL then everthing works fine, ... gcc gives the following message: ... some dummy comment but still the same warning. ...
    (comp.lang.c)
  • Re: conditional compile...
    ... i wrote the small program below to practice conditional compiling. ... define MYSYMBOL then everthing works fine, ... gcc gives the following message: ... The way to stop it printing `error` twice is to ...
    (comp.lang.c)
  • Re: conditional compile...
    ... define MYSYMBOL then everthing works fine, ... also why is compiler printing error twice. ... The compiler is outputting two different diagnostic messages because ... ....as the entire translation unit. ...
    (comp.lang.c)