I want to use macro to expand a function. So I wrote the following code:
#define INIT ( T ) \
struct T * init##T() { \
struct T * obj = ( struct T *)malloc( sizeof (struct T )); \
return obj; \
} \
I call the macro using the following :
INIT (mystruct);
error ::
error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘struct’
warning: data definition has no type or storage class [enabled by default]
I want to basically write generalized macro that accepts any structure, allocates space to an object of that structure and returns a value for the same.