preprocessor directives

R

rahul8143

hello,
how to interprete following #if in code? e.g. if i have a code
like
#if 0
somefunc();
else
somefunc();
#endif

also what is meaning of
#if !defined(__ENVVAR__)?
 
M

Mike Wahler

hello,
how to interprete following #if in code? e.g. if i have a code
like
#if 0
somefunc();
else
#else

somefunc();
#endif

The above (after my correction) means that only
the second call to 'somefunc()' (after the #else)
will become part of the translation unit. The
first call is excluded.
also what is meaning of
#if !defined(__ENVVAR__)?

It means that if, at this point, the preprocessor has not
encountered a definition of '__ENVVAR__', then everything
after the #if, up to the next #endif, #else, or #elif
will become part of the translation unit. If a definition
of '__ENVVAR' was already encountered, the inverse would
be true (everything between the #if and the next #endif,
#else, or #elif would be excluded).

This is all basic stuff. Which C textbook(s) are you
reading?

-Mike
 
S

sweet_thiruvonam

Hello,
Happy Harmony is the fastest growing matrimonial portal for
Indians.
You can email and IM other members without paying anything on this
site.
The amazing thing is that this site is totally free. Absolutely free.
Cannot believe? Then click on this link to visit and register Happy
Harmony.
http://www.happyharmony.com/?idAff=14
Background check is the new facility they have added now. You can do a
free
background check including age, address, phone numbers, property
owneship
information etc of anybody in the US.

Regards,
Resh
 
M

Martin Ambuhl

hello,
how to interprete following #if in code? e.g. if i have a code
like
#if 0

if 0 is non-zero (never), use the lines that follow up to the #endif,
#else, or #elif
(This is the normal way to comment out code, for example.)
somefunc();
else

'else' here means "please abort the compilation or at least warn about
this error".
somefunc();
#endif

also what is meaning of
#if !defined(__ENVVAR__)

['?' deleted from the above]

if __ENVVAR__ is not defined, use the lines that follow up to the
#endif, #else, or #elif
 
E

Eric Sosman

Martin said:
if 0 is non-zero (never), use the lines that follow up to the #endif,
#else, or #elif
(This is the normal way to comment out code, for example.)



'else' here means "please abort the compilation or at least warn about
this error".

Why? The material between `#if 0' and `#endif' must
be a valid stream of tokens, but need not be valid C.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top