On Fri, 30 Nov 2007 19:57:40 +0530, naunetr <na*****@gmail.comwrote
in comp.lang.c:
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?
The compiler is outputting two different diagnostic messages because
there are two different issues with your program.
thanks.
code:
/* #define MYSYMBOL 1 */
#if MYSYMBOL != 1
#error "Error"
#else
#include <stdio.h>
main() { puts("hello"); }
#endif
To add detail to Pete's explanation...
When MYSYMBOL is not defined to 1, the preprocessor eliminates
everything and the compiler only sees:
#error "Error"
....as the entire translation unit. C requires that every translation
unit requires at least one external definition, and yours does not
have one. That's the second diagnostic, the one referring to line 1,
although the text of the diagnostic is misleading.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html