MACRO Question: Returning pointer to a certain value
- by Andrei Ciobanu
Is it possible to write a MACRO that has a type and a value as its input parameters (MACRO(type,value)), and returns a valid pointer to a location that holds the submitted value.
This macro should perform like the following function, but in a more generic manner:
int *val_to_ptr(int val){
int *r = NULL;
r = nm_malloc(sizeof(*r));
*r = val;
return r;
}
Where nm_malloc() is a failsafe malloc.
The Macro usage should be compatible with this usage:
printf("%d",*MACRO(int,5));
Is it possible to achieve that ?