NOTE: This is NOT a duplicate of the question linked by Paul T, because I am asking if it is possible to determine if a type is of a certain broader incomplete type/kind at compile time, not if a symbol has been registered at compile time. This seems like a fundamental misunderstanding of the question.
I am writing a library in C that deals with pseudo-generic functions which take a type as an argument through a macro wrapper.
To spare the details (because they are rather complicated) there are two possible features that could help, I think:
Being able to detect if a type is a pointer at compile time. (No, the "use _Generic to test if you get ptrdiff_t from subtraction" trick won't work, because structures are a possibility, and you can't subtract structures.)
Being able to detect if a type is a struct at compile time. (If this was possible, then the aforementioned _Generic trick could be used if the type was detected as not being a struct.)
I've tried everything I could think of on Godbolt (even trying to compare types to incomplete anonymous structs and toying with __builtin_types_compatible_p) and wasn't able to find any solutions.
If anyone has any solutions I'd love to see them, otherwise I may just end up having to complicate the design a bit-- so not the end of the world if it's impossible, but it would be ideal if it can be done.
To give a basic idea of what one of these macros might look like or their expected output:
int *a; assert(!IS_STRUCT(a)); assert(IS_POINTER(a)); struct {} b; assert(IS_STRUCT(b)); assert(!IS_POINTER(b)); shouldn't throw any errors.
(void) &((object_of_unknown_type)[0]);meet your goal "to detect if a type is a pointer"?assertfor the example was misleading, in which case I apologize.IS_STRUCT()result would also be a constant expression.#define IS_STRUCT_SUBSTANTIAL(x) (sizeof(x) > sizeof(void*)), when true,xmust be astructand not an object pointer. Of course, when false,xcould be a pointer or a weestruct. Likely not generic enough, but a step. Knowing how this is used in the larger picture may help.