|
|
|
|
Syntax | Meaning |
---|---|
#ifdef MACRO-NAME text segment #endif |
|
#ifdef MACRO-NAME text segment 1 #else text segment 2 #endif |
|
#ifdef MACRO-NAME-1 text segment 1 #elif MACRO-NAME-2 text segment 2 [#else text segment 3] #endif |
|
#define COMPILE_IT (This defines COMPILE_IT to be the empty string !) #ifdef COMPILE_IT You can put any text here. The C-preprocessor will keep it when the above value is NON-ZERO #else You can put any text here. The C-preprocessor will keep it when the above value is ZERO #endif |
Output of the C pre-processor:
You can put any text here. The C-preprocessor will keep it when the above value is NON-ZERO |
How to run the program:
|
|
|
|
|
Example:
|
|
/* -------------------------------------------------------------- When here are no platform differences (standard C statements): just write the code without C pre-processor conditionals --------------------------------------------------------------- */ .... Standard C staments .... /* ----------------------------------------------------------------- When here are platform differences (uses platform dependent library function calls): write code for each platform with C pre-processor conditionals ------------------------------------------------------------------ */ #ifdef Linux Linux code #endif #ifdef Solaris Solaris code #endif .... |
gcc -Dsymbol ..... |
will tricket the C pre-processor to include the following definition:
#define symbol |
|
|
Syntax | Meaning |
---|---|
#if EXPRESSION text segment #endif |
|
#if EXPRESSION text segment 1 #else text segment 2 #endif |
|
#if EXPRESSION-1 text segment 1 #elif EXPRESSION-2 text segment 2 [#else text segment 3] #endif |
|
#define COMPILE_IT 1 #if COMPILE_IT You can put any text here. The C-preprocessor will keep it when the above value is NON-ZERO #else You can put any text here. The C-preprocessor will keep it when the above value is ZERO #endif |
Output of the C pre-processor:
You can put any text here. The C-preprocessor will keep it when the above value is NON-ZERO |
How to run the program:
|