Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Communicating with the Compiler | Compiler Directives and Advanced Control
C Preprocessing
course content

Conteúdo do Curso

C Preprocessing

C Preprocessing

1. Introduction to Preprocessing
2. Macros
3. Conditional compilation
4. Compiler Directives and Advanced Control

book
Communicating with the Compiler

Each #pragma directive can vary widely, but most follow a general pattern. The instruction being given is specified by the directive-name. The optional arguments depend on the specific directive and the compiler in use.

h

header

copy
1
#pragma directive-name [optional arguments]

Include Once

The old way to ensure the header is included only once is using #ifndef / #define guards. While still widely used and fully portable, it requires boilerplate and manual work.

c

main

h

config

copy
12345678
#include <stdio.h> #include "config.h" #include "config.h" // Reinclusion — NO duplication will occur int main() { printf("%s v%s\n", APP_NAME, APP_VERSION); return 0; }

Ensures that a header file is included in the compilation only once, even if it is included multiple times in different places. It is an alternative (and more modern) approach to the traditional #ifndef pattern.

c

main

h

config

copy
12345678
#include <stdio.h> #include "config.h" #include "config.h" // Reinclusion — NO duplication will occur int main() { printf("%s v%s\n", APP_NAME, APP_VERSION); return 0; }
question mark

What is the purpose of the #pragma once directive in a header file?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 1

Pergunte à IA

expand
ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

course content

Conteúdo do Curso

C Preprocessing

C Preprocessing

1. Introduction to Preprocessing
2. Macros
3. Conditional compilation
4. Compiler Directives and Advanced Control

book
Communicating with the Compiler

Each #pragma directive can vary widely, but most follow a general pattern. The instruction being given is specified by the directive-name. The optional arguments depend on the specific directive and the compiler in use.

h

header

copy
1
#pragma directive-name [optional arguments]

Include Once

The old way to ensure the header is included only once is using #ifndef / #define guards. While still widely used and fully portable, it requires boilerplate and manual work.

c

main

h

config

copy
12345678
#include <stdio.h> #include "config.h" #include "config.h" // Reinclusion — NO duplication will occur int main() { printf("%s v%s\n", APP_NAME, APP_VERSION); return 0; }

Ensures that a header file is included in the compilation only once, even if it is included multiple times in different places. It is an alternative (and more modern) approach to the traditional #ifndef pattern.

c

main

h

config

copy
12345678
#include <stdio.h> #include "config.h" #include "config.h" // Reinclusion — NO duplication will occur int main() { printf("%s v%s\n", APP_NAME, APP_VERSION); return 0; }
question mark

What is the purpose of the #pragma once directive in a header file?

Select the correct answer

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 1
Sentimos muito que algo saiu errado. O que aconteceu?
some-alt