description |
---|
06-02-2023 |
A conditional is a directive that INSTRUCTS the preprocessor to select whether or not to include a chunk of code in the final token stream passed to the compiler.
Three general reasons to use a conditional:
- A program may need to use different code depending on the machine or OS it is run on. Sometimes, data types or constants may not exist on the other system. The compiler would simply reject the program. With a preprocessing conditional, the bad code can be removed from the program when it is not valid.
- You may have a situation where you want to be able to compile the same source file into two different programs. One version might make frequent time-consuming consistency checks on its intermediate data, or print the values of those data for debugging and the other not.
- A conditional whose condition is always false is one way to exclude code from the program but keep it as a sort of comment for future reference.
So, what does a conditional look like in C?
#if
,#ifdef
, or #ifndef