Conditional Compile Flashcards

1
Q

What does the pre-processor do?

A

Examines code before compilation and resolves pre-processor directives.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the pre-processor directives?

A
  • # if, #elif, #else, #endif
  • # ifdef, #ifndef,
  • # define, #undef
  • # error
  • # pragma
  • # include
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What expressions can #if / #elif pre-processor directives evaluate?

A

They can evaluate constant expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do #if / #ifdef / #ifndef and #endif interact?

A

#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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In a pre-processor if statement, what happens to the code if the condition evaluates to false?

A

Nothing, the code between that if statement and the #elif/#endif is never compiled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the #define pre-processor statement do?

A

If allows the specifying of “compiler symbols” or “Macros”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the syntax of the #define pre-processor directive?

A

#define identifier replacement.
Any occurence of “identifier” in the rest of the code is replaced by “replacement”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the #undef pre-processor directive do?

A

It undoes the #define on a macro, freeing up the compiler symbol.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How long does a defined Macro persist?

A

Until the #undef directive is reached.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a compile time constant?

A

Using the #define directive to define a value.
Ex: #define PI 3.14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the benefit of compile time constants over variable constants?

A

They can be more memory efficient.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a Macro Expression?

A

Using a macro to define an expression that can be re-used.
Ex: #define MINUTES_IN_DAY (HOURS_IN_DAY * 60)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are macro chain expressions?

A

Linking multiple Macros together to create new Macros.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the #error pre-processor directive do?

A

It ends compilation when encountered and has an optional compilation error parameter.
#error error_paramter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can a DEBUG macro be used for conditional debugging?

A

If defined in the command line, a #ifdef directive can check DEBUG and perform debugging actions /prints.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you define a macro in the command line?

A

With the “-D” flag.
-D(symbol)
Ex: g++ -DDEBUG

17
Q

What are the predefined Macros?

A
  • __LINE__
  • __FILE__
  • __DATE__
  • __TIME__
  • __cplusplus
18
Q

What are the __cplusplus Macro values?

A
  • 199711L : Anything pre-C++11
  • 201103L : C++11
  • 201402L : C++14
  • 201703L : C++17
  • 202002L : C++20
  • 202302L : C++23
19
Q

What are the System Macros?

A
  • _WIN32
  • __APPLE__
  • __linux__
  • __GNUC__
  • __hpux