Conditional Compile Flashcards
What does the pre-processor do?
Examines code before compilation and resolves pre-processor directives.
What are the pre-processor directives?
- # if, #elif, #else, #endif
- # ifdef, #ifndef,
- # define, #undef
- # error
- # pragma
- # include
What expressions can #if / #elif pre-processor directives evaluate?
They can evaluate constant expressions.
How do #if / #ifdef / #ifndef and #endif interact?
#endif is used to cap an #if directive or series of #if directives. The scope of #if’s ends at the next #if or the #endif.
In a pre-processor if statement, what happens to the code if the condition evaluates to false?
Nothing, the code between that if statement and the #elif/#endif is never compiled.
What does the #define pre-processor statement do?
If allows the specifying of “compiler symbols” or “Macros”.
What is the syntax of the #define pre-processor directive?
#define identifier replacement.
Any occurence of “identifier” in the rest of the code is replaced by “replacement”.
What does the #undef pre-processor directive do?
It undoes the #define on a macro, freeing up the compiler symbol.
How long does a defined Macro persist?
Until the #undef directive is reached.
What is a compile time constant?
Using the #define directive to define a value.
Ex: #define PI 3.14
What is the benefit of compile time constants over variable constants?
They can be more memory efficient.
What is a Macro Expression?
Using a macro to define an expression that can be re-used.
Ex: #define MINUTES_IN_DAY (HOURS_IN_DAY * 60)
What are macro chain expressions?
Linking multiple Macros together to create new Macros.
What does the #error pre-processor directive do?
It ends compilation when encountered and has an optional compilation error parameter.
#error error_paramter
How can a DEBUG macro be used for conditional debugging?
If defined in the command line, a #ifdef directive can check DEBUG and perform debugging actions /prints.