Preprocessor
Include Guard Pattern
Include guards define a value once even if guarded text is seen again.
Include Guard Pattern
include_guard_pattern.c
#include <stdio.h>
#ifndef CONFIG_LIMIT
#define CONFIG_LIMIT 6
#endif
int main(void) {
int used = ;
int limit = 6;
int remaining = limit - used;
printf("remaining=%d\n", remaining);
return 0;
}
#include <stdio.h>
#ifndef CONFIG_LIMIT
#define CONFIG_LIMIT 6
#endif
int main(void) {
int used = ;
int limit = 6;
int remaining = limit - used;
printf("remaining=%d\n", remaining);
return 0;
}
#include <stdio.h>
#ifndef CONFIG_LIMIT
#define CONFIG_LIMIT 6
#endif
int main(void) {
int used = ;
int limit = 6;
int remaining = limit - used;
printf("remaining=%d\n", remaining);
return 0;
}
guard macro
`#ifndef` checks whether a guard name has already been defined.
one definition
The guarded block supplies one default value for the rest of the source.
expanded value
The executable trace uses the guarded value after preprocessing.