Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!ernie.viewlogic.com!sparks From: sparks@suntan.viewlogic.com (Alan Sparks) Newsgroups: comp.lang.c Subject: Re: Expansion of macro arguments in ANSI cpp. Message-ID: <1991May3.175308.28282@viewlogic.com> Date: 3 May 91 17:53:08 GMT References: <2610@otc.otca.oz> <208@tdatirv.UUCP> Sender: news@viewlogic.com (News Administrator) Organization: Viewlogic Systems, Inc., Marlboro, MA Lines: 65 Originator: sparks@power In article <208@tdatirv.UUCP>, sarima@tdatirv.UUCP (Stanley Friesen) writes: |> In article <2610@otc.otca.oz> grahamd@otc.otca.oz.au (Graham Dumpleton) writes: |> < |> <#define preone onepre |> <#define one two |> <#define addpre(arg) pre##arg |> < |> |> I believe that the ANSI standard requires that macro arguments be expanded |> before substitution into the macro body, and therefor before expansion of |> the macro itself into the source. |> |> Thus the answer is: |> |> pretwo |> |> |> |> I believe that this is *wrong* per the standard. |> (I do not actually have a copy present with me, so I could be wrong). |> -- |> --------------- |> uunet!tdatirv!sarima (Stanley Friesen) Paragraphs in the Standard suggest that AIX is correct (section A12.3): "... Unless the parameter in the replacement sequence is preceded by #, or preceded or followed by ##, the argument tokens are examined for macro calls and expanded as necessary, just before insertion." ".. Second, if the definition token sequence ... contains a ## operator, then just after replacement of the parameters, each ## is deleted, together with any whitespace on either side, so as to concatenate the adjacent tokens and form a new token." "In both kinds of macro, the replacement token sequence is repeatedly rescanned for more defined identifiers." So, this suggests that addpre(one) turns into pre ## one and (after concatenation), preone and finally, after rescan, onepre -Alan -- Alan Sparks voice: (508) 480-0881 Internet: sparks@viewlogic.com VIEWlogic Systems Inc., 293 Boston Post Rd. W., Marlboro MA 01752 Disclaimer: VIEWlogic didn't say this; I might have. Who's asking?