Preprocessing Commands
The main tasks of the preprocessor are to perform macro substitutions, link external files, conditional compilation, and perform text substitutions. More precisely, it executes all the directives it finds in the file.
Preprocessing prepares the file for future compilation stages, because, for example, the compiler has no idea what the #include
directive is.
Inclusion
The #include
directive is used to include the contents of other files into the source code of a program.
#include <stdio.h> // Include standard header file
#include "file.h" // Including a custom header file
Macro Definition
Macros in C allow you to define text substitutions. When the preprocessor finds a macro in the code, it replaces its value with the one specified in the #define
directive.
#define PI 3.14159
Wherever PI
appears in the code, it will be replaced with 3.14159
.
Conditional Compilation
Uses a whole set of commands (#if
, #ifdef
, #ifndef
, #else
, #elif
, #endif
) to include or exclude parts of code based on conditions. This is useful when working with platform-dependent code or for debugging.
Defined Macro
In the C programming language, there are special predefined macros that are automatically provided by the compiler.
main.c
1234567#include <stdio.h> int main() { printf("Number of line: %d\n", __LINE__); return 0; }
These were the main and most frequently used preprocessor directives. In addition to them, there are many more that we will also consider in this course.
Danke für Ihr Feedback!
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Awesome!
Completion rate improved to 5.56
Preprocessing Commands
Swipe um das Menü anzuzeigen
The main tasks of the preprocessor are to perform macro substitutions, link external files, conditional compilation, and perform text substitutions. More precisely, it executes all the directives it finds in the file.
Preprocessing prepares the file for future compilation stages, because, for example, the compiler has no idea what the #include
directive is.
Inclusion
The #include
directive is used to include the contents of other files into the source code of a program.
#include <stdio.h> // Include standard header file
#include "file.h" // Including a custom header file
Macro Definition
Macros in C allow you to define text substitutions. When the preprocessor finds a macro in the code, it replaces its value with the one specified in the #define
directive.
#define PI 3.14159
Wherever PI
appears in the code, it will be replaced with 3.14159
.
Conditional Compilation
Uses a whole set of commands (#if
, #ifdef
, #ifndef
, #else
, #elif
, #endif
) to include or exclude parts of code based on conditions. This is useful when working with platform-dependent code or for debugging.
Defined Macro
In the C programming language, there are special predefined macros that are automatically provided by the compiler.
main.c
1234567#include <stdio.h> int main() { printf("Number of line: %d\n", __LINE__); return 0; }
These were the main and most frequently used preprocessor directives. In addition to them, there are many more that we will also consider in this course.
Danke für Ihr Feedback!