cpp macro hack - RSVP - (nf)

ucbesvax!turner ucbesvax!turner
Wed Feb 23 17:42:36 AEST 1983


#N:ucbesvax:5200001:000:661
ucbesvax!turner    Feb 23 01:18:00 1983


/*
 * Does this work on your compiler?  The output should be as follows:

foo[0].name=hello, foo[0].val=1
foo[1].name=goodbye, foo[1].val=2

 * I would appreciate any and all responses to this question.  Basically,
 * I'm interested in the portability of these macro definitions.
 */
#define QUOTE(f) \
"\
f\
"

#define str_sym(sym) QUOTE(sym), &sym

int hello = 1,
    goodbye = 2;

struct
    {
    char *	name;
    int *	val;
    } foo [2] =
	{
	str_sym(hello),
	str_sym(goodbye)
	};

#define printv(x)\
    printf("%s.name=%s, %s.val=%d\n",\
	    QUOTE(x),\
	    x.name,\
	    QUOTE(x),\
	    *(x.val))

main()
{
    printv(foo[0]);
    printv(foo[1]);
}





More information about the Comp.lang.c mailing list