cpp: Conditional Uses
1
1 4.1 Conditional Uses
1 ====================
1
1 There are three general reasons to use a conditional.
1
1 * A program may need to use different code depending on the machine
1 or operating system it is to run on. In some cases the code for
1 one operating system may be erroneous on another operating system;
1 for example, it might refer to data types or constants that do not
1 exist on the other system. When this happens, it is not enough to
1 avoid executing the invalid code. Its mere presence will cause the
1 compiler to reject the program. With a preprocessing conditional,
1 the offending code can be effectively excised from the program when
1 it is not valid.
1
1 * You may want to be able to compile the same source file into two
1 different programs. One version might make frequent time-consuming
1 consistency checks on its intermediate data, or print the values of
1 those data for debugging, and the other not.
1
1 * A conditional whose condition is always false is one way to exclude
1 code from the program but keep it as a sort of comment for future
1 reference.
1
1 Simple programs that do not need system-specific logic or complex
1 debugging hooks generally will not need to use preprocessing
1 conditionals.
1