I am trying to write a macro to assist with object oriented programming in C. As I store the class information in a constant struct, I need to create a macro that does the following:
_info
to get the name of the desired classInfo structdestroyObject
function with a pointer to the class struct and the object itselfAn example:
queue_t* p = NULL;
delete(p);
delete
should expand to:
destroyObject(&(queue_t_info), p);
I tried using this macro, but I can't get to to work:
#define delete(X) (destroyObject(&(typeof(*X)##_info), X))
I'm having trouble with the typeof part to work correctly.
typeof
isn't macro, it is language construction and it is expanded by compiler, not preprocessor. Since preprocessing goes before compilation, macro can't access typeof
result.
Your delete(p)
is expanded to: (destroyObject(&(typeof(*p)_info), p))
. (You can see it by -E
gcc flag)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With