Redefining or changing macro value

You can undefine it and define again: #include <iostream> #define AAA 13 int main() { #undef AAA #define AAA 7 std::cout << AAA; } outputs: 7 Please note that statements that start with # are preprocessor directives that are taken care of before the code is even compiled. In this case, this constant AAA will … Read more

How can I pass a macro definition from “make” command line arguments (-D) to C source code?

Call the make command this way: make CFLAGS=-Dvar=42 And be sure to use $(CFLAGS) in your compile command in the Makefile. As @jørgensen mentioned, putting the variable assignment after the make command will override the CFLAGS value already defined in the Makefile. Alternatively, you could set -Dvar=42 in another variable than CFLAGS and then reuse … Read more

Are empty macro arguments legal in C++11?

If I understand correctly, empty macro argument is allowed since C99 and C++0x(11). C99 6.10.3/4 says: … the number of arguments (including those arguments consisting of no preprocessing tokens) shall equal the number of parameters … and C++ N3290 16.3/4 has the same statement, while C++03 16.3/10 mentions: … any argument consists of no preprocessing … Read more