Is it possible to do a nullity check and an access in a macro?
Eg:
#define LOG(mystruct, severity, format, ...) ({ \
severity_t current = ERROR; \
if (mystruct) { \
current = mystruct->error_level; \
} \
if (severity >= current) { \
... //handle logging
} \
})
If I call this with LOG(NULL, DEBUG, "test %s", "one");
I get an error as such:
error: member reference base type 'void' is not a structure or union
note: expanded from macro 'LOG'
current = mystruct->error_level;
mystruct is defined as:
typedef struct mystruct_t {
severity_t error_level;
}
I want to allow the possibility of working with a NULL mystruct
. Eg: case of when there is an error creating the structure itself.