Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!samsung!umich!sharkey!amara!mcdaniel From: mcdaniel@amara.uucp (Tim McDaniel) Newsgroups: comp.lang.c Subject: Re: Commas in macro arguments Message-ID: Date: 10 Apr 90 19:46:14 GMT References: <1990Mar22.203048.18491@dde.dk> <1990Mar23.164301.14975@utzoo.uucp> <246@samna.UUCP> <4665@jhunix.HC <701@mwtech.UUCP> Sender: news@amara.UUCP Organization: Applied Dynamics Int'l. Lines: 37 In-reply-to: martin@mwtech.UUCP's message of 3 Apr 90 12:57:18 GMT esp_003@jhunix.UUCP (Stdnt003) writes: >#define call(a, b) a ## b /* (See K&R for details) */ ("K&R" means 2nd Edition Kernighan and Richie) Excuse me if this has already been pointed out, but it's my understanding that this would be illegal for the purpose. Page 230 of K&R2: "just after replacement of the parameters, each ## is deleted, together with any white space on either side, so as to concatenate the adjacent tokens and form a new token. The effect is undefined if invalid tokens are produced..." The example on page 231 is more explicit: "#define cat(x, y) x ## y ... the call cat(cat(1,2),3) is undefined: the presence of ## prevents the arguments of the outer call from being expanded. Thus it produces the token string cat ( 1 , 2 )3 and ')3' (the concatenation of the last token of the first argument with the first token of the second) is not a legal token." I conclude that call(foo,(a,b)) need not produce foo(a,b) It conceptually first produces the token "foo(", which is not a legal token. (Of course, since the behavior is undefined, the compiler could do what Stdnt003 expected---but it need not, and an integrated preprocessor-compiler program probably won't.) -- Tim McDaniel Applied Dynamics International, Ann Arbor, MI Internet: mcdaniel%amara.uucp@mailgw.cc.umich.edu UUCP: {uunet,sharkey}!amara!mcdaniel