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:
- Take the type of the object (typeof the derefenced pointer)
- Append
_infoto get the name of the desired classInfo struct - Take the address of that symbol so it can be passed to the function
- Call the
destroyObjectfunction with a pointer to the class struct and the object itself
An 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.
intwhen passed a reference to an integer? - charliehorse55