Possible to #if in case an enum exists?
-
Is it possible to somehow check during compile time if an enum exists, i.e. something like this:
typedef enum {
MY_ENUM_VALUE = 0
} myEnum_e;#define DOES_ENUM_EXIT(__ARG__) ??? What goes here???
if (DOES_ENUM_EXIT(myEnum)) { // Will evaluate to TRUE during compile time since myEnum_e exists
}I know that I could achieve something similar easily be using
#define MY_ENUM_VALUE (0)
instead, but then my code wouldn't be type safe.
-
Is it possible to somehow check during compile time if an enum exists, i.e. something like this:
typedef enum {
MY_ENUM_VALUE = 0
} myEnum_e;#define DOES_ENUM_EXIT(__ARG__) ??? What goes here???
if (DOES_ENUM_EXIT(myEnum)) { // Will evaluate to TRUE during compile time since myEnum_e exists
}I know that I could achieve something similar easily be using
#define MY_ENUM_VALUE (0)
instead, but then my code wouldn't be type safe.
-
Is it possible to somehow check during compile time if an enum exists, i.e. something like this:
typedef enum {
MY_ENUM_VALUE = 0
} myEnum_e;#define DOES_ENUM_EXIT(__ARG__) ??? What goes here???
if (DOES_ENUM_EXIT(myEnum)) { // Will evaluate to TRUE during compile time since myEnum_e exists
}I know that I could achieve something similar easily be using
#define MY_ENUM_VALUE (0)
instead, but then my code wouldn't be type safe.
-
No, because the
#define
statement is handled by the preprocessor, and the enum value is not known until it is fed into the compiler, which comes later.