I need to detect by a macro at compile time if a struct has a member. I've tried offsetof(struct object, a_field) but it causes error to be issued at compilation about non existing field. Is there some other method to check if a C struct has a field?
I need this for a macro
MESSAGE(obj, method, ...) obj->method(obj, ##__VA_ARGS);
So that I could use it also on non virtual methods, like:
MESSAGE(obj, method, ...) method(obj, ##__VA_ARGS);
So in general to detect if there is method member and if so, call it as obj->member(obj, …) and as member(obj, …) otherwise.
Types are known at compilation time. This means you cannot use a structure field which has not been declared in such a structure. You can use the field, and get an error from the compiler if the provider of such structure has not declared the field properly, but there's no way to check it conditionally.