In C/C++, is there a directive similar to #ifndef for typedefs?

后端 未结 11 2234
太阳男子
太阳男子 2020-12-15 16:03

If I want to define a value only if it is not defined, I do something like this :

#ifndef THING
#define THING OTHER_THING
#endif

What if

11条回答
  •  天涯浪人
    2020-12-15 16:22

    This might not directly answer the question, but serve as a possible solution to your problem.

    Why not try something like this?

    #define DEFAULT_TYPE int // just for argument's sake
    #ifndef MY_COOL_TYPE
         #define MY_COOL_TYPE DEFAULT_TYPE
    #endif
    typedef MY_COOL_TYPE My_Cool_Datatype_t;
    

    Then if you want to customize the type, you can either define MY_COOL_TYPE somewhere above this (like in a "configure" header that is included at the top of this header) or pass it as a command line argument when compiling (as far as I know you can do this with GCC and LLVM, maybe others, too).

提交回复
热议问题