Preprocessor Flashcards
What does the following do?
- # include
- # include “filename”
- # define name [value]
- Insert a library file’s contents into this file. Compier looks in default search path
- 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
- Creates a preprocessor symbol (“variable”) - defines a macro.
How does the preprocessor work?
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 do you have the compiler use the debug command and how does the code work in the program?
ifdef Debug
clang -DDEBUG
examples:
//debug only code
//production code
How do you define a const?
const int = 4;
how do you define a typedef?
typedef float dollars;
now float and dollars are interchangable
What are the compiling steps for the preprocessor?
Step 1: C program -> [Preprocessor] -> Modified C program (literally copied in)
Step 2: Modified C program ->[Compiler]-> object code
What are the 3 types of preprocessing directives
- Macros
- File Inclusion
- Conditionals
What are 2 ways macros can be used?
- To define a constant (#DEFINE THENUM 1)
- Like a function (see image)
How are conditionals used?
if (statement)
code runs
It is important to note, variables must be #define constants to use them in the statements