The simple trick that I always use is to override the macro on the line you want to test. When you compile the code, the preprocessor will complain and tell you where the previous definition was.
Example:
test.cpp contains:
#include "test.h" int main() { #define SOMEMACRO 1 return 0; }
test.h contains:
#define SOMEMACRO 2 int foo();
when compiling test.cpp, I get this error message:
test.cpp:5:0: warning: "SOMEMACRO" redefined [enabled by default] In file included from test.cpp:1:0: test.h:1:0: note: this is the location of the previous definition
I tested GCC, but Visual Studio does the same.
source share