Conflicting enum issue

This is a discussion on Conflicting enum issue within the C Programming forums, part of the General Programming Boards category; Here is the scenario; A header uses an enum as follow:- Code: typedef enum { NONE, FEW, SOME, MORE, MOST, ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    14

    Question Conflicting enum issue

    Here is the scenario;
    A header uses an enum as follow:-
    Code:
    typedef enum {
     NONE,
     FEW,
     SOME,
     MORE,
     MOST,
     ALL
    } qty;
    This header is included in many source files.

    A particular source file has the following enum:-
    Code:
    typedef enum {
     MINORITY,
     SOME,
     MAJORITY
    } my_qty;
    This source file does not include the header file mentioned earlier, However, due to some new implementation required in the source file, it needed to include the header file. Of course, a compilation error is generated because the label SOME is used in two different enums.

    One easy way is to change the SOME in my_qty enum to a different label and make updates throughout the source file accordingly.

    Assuming that I'm not allowed to make the change I previously mentioned, is there any way to include the header and not generate compilation error? Is there any way to still use the locally define SOME in the source file for its internal use, BUT not utilize the SOME in the included header enum?

    Note: The new implementation does not require usage of the header enumeration.

    Hope my questions are clear enough. Thanks in advance

  2. #2
    Registered User
    Join Date
    Jun 2006
    Posts
    14
    One way found was to 'fool' the compiler

    Header File:-

    Code:
    #ifndef ENUM_TYPE
    typedef enum
    {
     ...
    }
    qty;
    #endif
    Source file:-

    Code:
    #define ENUM_TYPE
    #include "header"
    #undef ENUM_TYPE
    So when the source file is being compiled, the enum from the header wont be referred to since its not declared. However, not sure if this would cause any problems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 08-23-2008, 02:16 PM
  2. enum [tag] [: type] Is this non-standard?
    By HyperShadow in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2007, 10:29 PM
  3. enum switchcase and windows message q
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 11-27-2006, 01:16 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Switch case and enum help
    By SomeCrazyGuy in forum C++ Programming
    Replies: 9
    Last Post: 04-21-2005, 09:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21