Somewhere in the headers there is a type definition

typedef enum { SUCCESS = 0 } status; 

Below the code there is a need to re-type

 typedef enum { FAILURE = 0 } status; 

Obviously, you can defend yourself with preprocessor directives.

 #ifndef STATUS #define STATUS typedef enum { SUCCESS = 0 } status; #endif 

But, unfortunately, you can not change the headers. Therefore, the question is: how to check when defining a typedef that such a typedef is not yet defined?

  • 2
    @asdf None. - Costantino Rupert
  • 3
    or it can define its status type in a separate namespace and use it. - KoVadim
  • Strange your needs. Strongly like a perversion. Still, is 0 SUCCESS or FAILURE? And is it necessary to push them into one type? (The functions that return them - are they different?) - alexlz
  • one
    I still do not understand the purpose of such a perversion what? Author, please reply. At the same time there was a thought that here you can use templates. Well, they can do all sorts of tricks. Including and answer tricky questions from programmers, for example, whether it’s a POD type or not. - gecube
  • 2
    Well, so, tell about that what warnings the compiler issued and on what lines. Otherwise, the value of this issue for me to strive for zero, because it is not clear what is the initial situation. - gecube 2:01 pm

1 answer 1

Check - no way. But you can do this:

 //то что есть изначально typedef enum { SSUCCESS = 0 } status; //то что делаем мы #ifndef STATUS #define STATUS status #else #undef STATUS #define STATUS status #endif //далее по коду typedef enum { FAILURE = 0 } status_def1; #ifndef STATUS #define STATUS status_def1 #else #undef STATUS #define STATUS status_def1 #endif //и во всех случаях, используем STATUS !!! STATUS eResult; 
  • Yes, great. Now try to compare eResult with FAILURE . - Costantino Rupert
  • !Yes, great. Now try to compare eResult with FAILURE. @ Kitty_khohet_kushat pastebin.com/VaH1Kz1p - vv2cc
  • Another thing is that all this is not very convenient and crutches, but this business is already a programmer who decided to use a similar trick :) - vv2cc
  • one
    It is not easier to construct #ifndef STATUS #define STATUS status #else #undef STATUS #define STATUS status #endif Reduce to #ifdef STATUS #undef STATUS #endif #define STATUS status ???????? - gecube