I'm trying to pass the value of a C macro to the preprocessor with the -Dmacro=value option of gcc. However, it doesn't do what i expect. This is the basics of my code:
#define T0 0
#define T1 0
#define T2 0
#define T3 0
int main(){
int f[9];
start(f[T0], f[T1], f[T2], f[T3]);
return 0;
}
Running gcc -DT3=1 -E
shows the preprocessor does not replace the original value of T3. What am i missing, and how can the value be passed properly?
I usually pass macro definitions from "make command line" to a "makefile" using the option : -Dname=value. The definition is accessible inside the makefile. I also pass macro definitions from the "makefile" to the "source code" using the similar compiler option : -Dname=value (supported in many compilers).
The -E option causes gcc to run the preprocessor, display the expanded output, and then exit without compiling the resulting source code. The value of the macro TEST is substituted directly into the output, producing the sequence of characters const char str[] = "Hello, World!" ; .
4. Which gcc option undefines a preprocessor macro? Explanation: None.
You can't. Macros are expanded by the Preprocessor, which happens even before the code is compiled. It is a purely textual replacement.
Afaik that switch will define a macro, but your code then overrides it back to 0. Remove that define from your code or surround it with ifdef and it should be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With