Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Preprocessing Commands | Introduction to Preprocessing
C Preprocessing

bookPreprocessing 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

main.c

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

question mark

Which preprocessor directive should be used for including new files?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 3

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Suggested prompts:

Kysy minulta kysymyksiä tästä aiheesta

Tiivistä tämä luku

Näytä käytännön esimerkkejä

Awesome!

Completion rate improved to 5.56

bookPreprocessing Commands

Pyyhkäise näyttääksesi valikon

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

main.c

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

question mark

Which preprocessor directive should be used for including new files?

Select the correct answer

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 3
some-alt