ctypesmacros

Is there a way to determine whether a type is not defined?


I have a type Type_##type dependent on a certain macro type_create:

#define type_create(type) { \
    typedef struct { \
        type* ptr, \
    } Type_##type; \

and I have a few macros dependent on it. Now I am wondering if I can do something like #ifndef for a type, for example,

#ifndef Type_int
type_create(int);
#endif

except for types.


Solution

  • A solution could be to define Type_int both as a type and a macro:

    #define Type_int Type_int
    

    The preprocessor will replace Type_int with, well, Type_int , but now you can do a #ifdef Type_int :

    #define type_create(type) \
        typedef struct { \
            type* ptr; \
        } Type_##type
    
    
    #ifndef Type_int
    #define Type_int Type_int
    type_create(int);
    #endif
    
    
    // in source:
    #ifdef Type_int
        Type_int a, b;
    #endif