> Online tutorial : ifdef in c
Showing posts with label ifdef in c. Show all posts
Showing posts with label ifdef in c. Show all posts

ifdef in c

#ifdef, Conditional compilation directives

Syntax:

#if
#else
#endif

#if
#elif
#endif


1)The compiler only compiles the lines that follow the #if directive when evaluates to non-zero.
2)Otherwise, the compiler skips the lines that follow until it encounters the matching #else or #endif.
3)If the expression evaluates to false and there is a matching #else, the lines between the #else and the #endif are compiled.
4)#if directives can be nested, but matching #else and #endif directives must be in the same file as the #if.
5)#elif is like #else except the else block is only compiled if the expression after #elif is non-zero.


#ifdef  evaluates to 1 if the symbol specified by has been previously
defined with a #define directive.


Example

#ifdef DEBUG
printf("Total space %d\n", space);
#endif