Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kazssym
Copy link

@kazssym kazssym commented Oct 3, 2021

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.

@kazssym kazssym marked this pull request as ready for review October 4, 2021 11:52
Copy link
Collaborator

@VolkerEnderlein VolkerEnderlein left a 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
Copy link
Collaborator

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.

Copy link
Author

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?

Copy link
Collaborator

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 )

Copy link
Collaborator

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

<Inventor/errors/SoDebugErrors.h> leaves macro ERROR defined to an undeclared symbol
2 participants