pardo@june.cs.washington.edu (David Keppel) (07/16/88)
I'm having trouble #defining a macro that takes an argument that should be dereferenced and set if not NULL, otherwise not dereferenced. More accurately, I can do it, but it doesn't "feel right". Wanted: x = ZORCH( v, p ); y = ZORCH( v, NULL ); I tried: #define ZORCH( v, p ) \ ((p)?((*(p))=(v->size)):0, f(v->bork)) This works when p really points at something. Neither pcc nor gcc will compile it when p is NULL (on an Ultrix VAX, anyway). Thinking "aha! a cast behaves like an assignment to an anonymous variable", I tried the following, which is uglier but does seem to work: #define ZORCH( v, p ) \ ((p)?((*((unsigned int *)p))=(v->size)):0, f(v->bork)) Ok, great. It works. It seems wierd to me, and that probably means that I don't understand something. Comments? (Please e-mail) ;-D on ( Better dead then mellow ) Pardo pardo@cs.washington.edu {rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo