| Topic: |
DEVELOP > C |
| User: |
"naunetr" |
| Date: |
30 Nov 2007 08:27:40 AM |
| Object: |
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
.
|
|
| User: "Jack Klein" |
|
| Title: Re: conditional compile... |
30 Nov 2007 10:59:21 PM |
|
|
On Fri, 30 Nov 2007 19:57:40 +0530, naunetr <naunetr@gmail.com> wrote
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
.
|
|
|
|
| User: "pete" |
|
| Title: Re: conditional compile... |
30 Nov 2007 05:26:52 PM |
|
|
naunetr wrote:
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.
It means that with MYSYMBOL commented out, this:
#error "Error"
becomes your whole program,
and that's not enough of a program to compile.
code:
/* #define MYSYMBOL 1 */
#if MYSYMBOL != 1
#error "Error"
#else
#include <stdio.h>
main() { puts("hello"); }
#endif
--
pete
.
|
|
|
|
| User: "Chris Dollin" |
|
| Title: Re: conditional compile... |
30 Nov 2007 08:41:12 AM |
|
|
naunetr wrote:
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.
You need real code. A static declaration will do; comments won't.
also why is compiler printing error twice. it looks ugly. is there a
way to make it print error once only?
Pass [1]. But who cares? The way to stop it printing `error` twice is to
stop it printing `error` at all. If there's a real error error, the
repeated text is likely to be the least of your problems.
[1] If there is, it will be compiler specific. gcc has many many command-
line options, many of which control diagnostic reports.
--
Chris "it was deliberate" Dollin
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England
.
|
|
|
|

|
Related Articles |
|
|