16 /* print out if compiled on Win32 */
17 printf("WIN32\n" );
18 #else
19 printf("?\n");
20 #endif
21
22
return(0);
23 }
Example Execution
Let’s look at the Win32 and UNIX output.
Win32 Output
C:\>ifdef1.exe
WIN32
UNIX Output
obsd32# gcc –o ifdef1 ifdef1.c
obsd32# ./ifdef1
OpenBSD
Analysis
■
At line 12, an ifdef pre-compiler directive is used to determine if the operating
system that the program is being compiled on is OpenBSD. If it is, the code at
line 14 will be compiled, not the code at line 17.
■
At line 15, an ifdef pre-compiler directive is used to determine if the operating
system that the program is being compiled on is a Win32 platform. If it is, the
code at line 17 will be compiled, not the code at line 14.
■
At lines 14 and 16, the printf() function is called ...