You can invoke the preprocessor on its own using "-E" flag. There's not much more to it than a (conditional) text substitution tool. This little example might help..We only need to see the last few lines (hence tail -15) . Note the preprocessor lines have been replaced with whitespace. This is effectively the code the compiler actually attempts to compile..If we ensure "SUPPRESS_LINEFEED" is defined then the preprocessor changes the code the compiler will see....the "putchar" has gone.
Hopefully it makes sense now why the compiler complained when you moved your code around. It was, in effect, the same as a cut 'n' paste.
Code:
foo@sdu:/wrk/T$ cat x.c#include <stdio.h>intmain(void){ printf("Hello World");#ifndef SUPPRESS_LINEFEED putchar('\n');#endif return 0;}Code:
foo@sdu:/wrk/T$ gcc -E x.c | tail -15# 902 "/usr/include/stdio.h" 3 4# 2 "x.c" 2# 3 "x.c"intmain(void){ printf("Hello World"); putchar('\n'); return 0;}Code:
foo@sdu:/wrk/T$ gcc -DSUPPRESS_LINEFEED -E x.c | tail -15# 902 "/usr/include/stdio.h" 3 4# 2 "x.c" 2# 3 "x.c"intmain(void){ printf("Hello World"); return 0;}Hopefully it makes sense now why the compiler complained when you moved your code around. It was, in effect, the same as a cut 'n' paste.
Statistics: Posted by swampdog — Sat Feb 03, 2024 1:38 pm