Preprocessor Flashcards

1
Q

What does the following do?

  1. # include
  2. # include “filename”
  3. # define name [value]
A
  1. Insert a library file’s contents into this file. Compier looks in default search path
  2. insert a user file’s contents into this file - directive causes the contents of a specified file to be included in a program. AKA headerfiles, include files. Compiler searches for the file in the current directory
  3. Creates a preprocessor symbol (“variable”) - defines a macro.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does the preprocessor work?

A

The input is a C program (possibly containing directives). The preprocessor executes these directives, removing them in the process. The preprocessor’s output goes directly into the compiler

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

How do you have the compiler use the debug command and how does the code work in the program?

A

ifdef Debug

clang -DDEBUG

examples:

//debug only code

//production code

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

How do you define a const?

A

const int = 4;

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

how do you define a typedef?

A

typedef float dollars;

now float and dollars are interchangable

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

What are the compiling steps for the preprocessor?

A

Step 1: C program -> [Preprocessor] -> Modified C program (literally copied in)

Step 2: Modified C program ->[Compiler]-> object code

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

What are the 3 types of preprocessing directives

A
  1. Macros
  2. File Inclusion
  3. Conditionals
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are 2 ways macros can be used?

A
  1. To define a constant (#DEFINE THENUM 1)
  2. Like a function (see image)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How are conditionals used?

A

if (statement)

code runs

It is important to note, variables must be #define constants to use them in the statements

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