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.
header.h
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.
main.c
config.h
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.
main.c
config.h
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; }
Merci pour vos commentaires !
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Posez-moi des questions sur ce sujet
Résumer ce chapitre
Afficher des exemples du monde réel
Awesome!
Completion rate improved to 5.56
Communicating with the Compiler
Glissez pour afficher le menu
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.
header.h
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.
main.c
config.h
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.
main.c
config.h
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; }
Merci pour vos commentaires !