I am doing some macros like
#define report_msg(type,msg_str).......my_special_##type(......)
#define report_error(msg_str) report_msg(ERROR,msg_str)
It works perfect under linux while when I compile with visual studio 2010 express, I see it gives error that
error C3861: 'my_special_0': identifier not found
The reason is that "ERROR" is interpreted as 0. And when I use "Go to defination" in MSVC, it goes to WinGDI.h
/* Region Flags */
#define ERROR 0
Question is why this WinGDI.h is included? How can I eliminated it without touching the code?
Solution 1: Swap include orders of some headers -> tedious task
Solution 2:
Put NOGDI
in preprocessor. In Visual Studio: Project Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions -> add NOGDI
.
Explanation:
Paul pointed me in the right direction. I don't use precompiled headers, so I don't include stdafx.h
. My problem is related to Linux vs. Windows libraries.
In my case I use a library, which defines the constant 'ERROR' for log messages. For timestamps ctime.h
is included, which uses Windows.h
/WinGDI.h
.
This is why macros are evil. I've seen cases where TRUE and FALSE are defined with different values in different headers. In any project of decent size it may become tedious to follow the chains of headers. Try
#undef ERROR
#define report_msg(type,msg_str).......my_special_##type(......)
#define report_error(msg_str) report_msg(ERROR,msg_str)
and hope that the "real" definition of ERROR is not needed after these statements.
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