MACRO Question: Returning pointer to a certain value

Posted by Andrei Ciobanu on Stack Overflow See other posts from Stack Overflow or by Andrei Ciobanu
Published on 2010-06-08T09:07:41Z Indexed on 2010/06/08 9:12 UTC
Read the original article Hit count: 152

Filed under:
|
|

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 ?

© Stack Overflow or respective owner

Related posts about c

    Related posts about macros