The #undef directive cancels a previously defined preprocessor macro, allowing developers to constrain macro scope to specific code sections or redefine macro values safely.
#undef Preprocessor Example
#include <stdio.h>
#define BUFFER_SIZE 512
void process_data(void) {
printf("Processing with buffer size: %d\n", BUFFER_SIZE);
}
// Undefine macro to prevent scope leakage
#undef BUFFER_SIZE
int main(void) {
process_data();
// BUFFER_SIZE is no longer defined here
return 0;
}
Comments and corrections