Examples of #if and #elif
Directives
/************************************************************************
* The following example uses the #if and #elif directives to assign *
* values to an array. *
************************************************************************/
#include <stdio.h>
int main(void)
{
int i;
char *arrayname = "realarray";
int realarray[] = { 1, 2, 3 };
int array1[] = { 4, 5, 6 };
int array2[] = { 7, 8, 9 };
#if ( (defined(LEVEL1)) && (TEST > 1) )
for (i = 0; i < 3; i++)
realarray[i] = array1[i];
arrayname = "array1";
#elif (defined(LEVEL2))
for (i = 0; i < 3; i++)
realarray[i] = array2[i];
arrayname = "array2";
#endif
printf("realarray[] now has the contents of %s[]\n", arrayname);
/* Assuming only LEVEL2 is defined, the expected output is:
realarray[] now has the contents of array2[] */
}