Creating Conditionals

Just as you can have conditionals within your C code that may or may not execute code depending on whether a condition is true or false, you can write C preprocessor conditionals. These are directives that instruct the preprocessor to do something (or not do something) based on certain criteria. Unlike your C conditionals, which are checked during execution of an application, C preprocessor conditionals are tested during the preprocessor stage (just before compilation).

There are a number of conditional directives in the C preprocessor (Table 8.1), allowing for relatively intricate examples.

Table 8.1. These directives are used to create conditionals for the C preprocessor.
Conditional Directives
DirectiveEffect
#ifIncludes ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.