-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rework the ERROR definition problem with Win32 #469
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution to Coin development. Please see the comment attached to your PR.
@@ -39,8 +39,12 @@ | |||
// Avoid problem with Microsoft Win32 API headers (yes, they actually | |||
// #define ERROR -- in wingdi.h). | |||
#if defined(ERROR) | |||
#define SODEBUGERROR_STORE_ERROR_DEF ERROR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than defining an additional enum I would use the following sequence in the SoDebugError
header and source files:
#if defined(_WIN32)
#pragma push_macro("ERROR")
#undef ERROR
#endif
< code that defines enum in header and that uses enum in source >
#if defined(_WIN32)
#pragma pop_macro("ERROR")
#endif
This will save the value of the ERROR
macro on the stack with the push_macro
command, undef the macro in the current context and restore its previous value after the pop_macro
command.
Although push_macro
and pop_macro
are Microsoft preprocessor extensions (defined at least since VS6 from 1998) they are also widely supported from in Intel C++, GCC and Clang compilers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good, but SoDebugError::ERROR
will become an error then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in SoDebugError.h
and SoDebugError.cpp
, the ERROR
preprocessor token is undefined and a new enum constant SoDebugError::ERROR
can be defined without conflicts. But in other sources that eval SoDebugError::ERROR
and include windows.h
you need to insert the same sequence. A quick grep in the entire Coin3d repository revealed only one place in SoWin.cpp
where SoDebugError::ERROR
is used. This push_macro
/pop_macro
is used for instance in Google protobuf (see here )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall I do the necessary changes to the files or will you adapt the PR?
This change will solve the name collision problem with the Win32 API.
I hope it is safe to redefine
ERROR
as an enum constant instead of a preprocessor macro.Fixes #468.