Richard Williams
Richard Williams

Reputation: 301

Conflict caused by #define macro and enum using same name

I am trying to integrate NVIDIA's PhysX into my Linux codebase. In some of its header files, it defines the following enums:

physxvisualdebuggersdk/PvdErrorCodes.h

struct PvdErrorType
{
  enum Enum
  {
    Success = 0,
    NetworkError,
    ArgumentError,
    InternalProblem
  };
};

physxprofilesdk/PxProfileCompileTimeEventFilter.h:

struct EventPriorities
{
  enum Enum
  {
    None,       // the filter setting to kill all events
    Coarse,
    Medium,
    Detail,
    Never       // the priority to set for an event if it should never fire.
  };
};

Which results in the following compile errors:

/usr/local/include/PhysX3/physxvisualdebuggersdk/PvdErrorCodes.h:36:4: error: expected identifier before numeric constant
    Success = 0,
    ^
/usr/local/include/PhysX3/physxvisualdebuggersdk/PvdErrorCodes.h:36:4: error: expected ‘}’ before numeric constant
/usr/local/include/PhysX3/physxvisualdebuggersdk/PvdErrorCodes.h:36:4: error: expected unqualified-id before numeric constant

and

/usr/local/include/PhysX3/physxprofilesdk/PxProfileCompileTimeEventFilter.h:46:4: error: expected identifier before numeric constant
    None,  // the filter setting to kill all events
    ^
/usr/local/include/PhysX3/physxprofilesdk/PxProfileCompileTimeEventFilter.h:46:4: error: expected ‘}’ before numeric constant
/usr/local/include/PhysX3/physxprofilesdk/PxProfileCompileTimeEventFilter.h:46:4: error: expected unqualified-id before numeric constant

I have determined that this is because X11/X.h #defines both 'None' and 'Success'. I have confirmed that this is the issue as, if I #undef both 'None' and 'Success', I no longer have the errors. However, this obviously isn't a desirable thing to do.

My question is: As a developer who has to use both these headers, what is the correct course of action for me to take? Should I report it to NVIDIA as a bug and wait for a fix or is there something that I can do myself to resolve the issue (besides #undef)?

Thanks for your time!

Upvotes: 6

Views: 3265

Answers (1)

Mark B
Mark B

Reputation: 96291

The sanest course of action is to separate the implementations in such a way that within your project you don't including BOTH conflicting headers in the same source file. One file deals with X and one with PhysX and then your application ties the two implementations together.

Upvotes: 1

Related Questions