View Single Post
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#19
Compilation of C++ (and C) happens in a couple of different steps:

- Preprocessor (handles #include, #define, #if, #ifdef and the like)
- Compiler (parses all the code and builds an abstract representation, AST, that's then changed in different ways for some kinds of optimization and other compiler magic)
- Generate assembler (the compiler backend translates the AST to platform specific assembler)
- Assembler (the assembler read the assembly code and translates it into object code with link references as special markers)
- Linker (links the compilation units (object code blobs) together and fixes link markers to reference shared libraries)

The preprocessor can be thought of as just a file manipulator that puts together the file that is to be parsed by the compiler. #include is a character by character insertion of another file.

As explained above, #ifdef is the classical way of preventing multiple includes.
 

The Following User Says Thank You to Joorin For This Useful Post: