Xref: utzoo comp.lang.c:39299 comp.std.c:4837 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!sdd.hp.com!apollo!vinoski From: vinoski@apollo.HP.COM (Stephen Vinoski) Newsgroups: comp.lang.c,comp.std.c Subject: Re: Question on ANSI ## pre-processor operator. Message-ID: <51951216.20b6d@apollo.HP.COM> Date: 15 May 91 19:27:00 GMT References: <28302040.69ED@deneva.sdd.trw.com> <519416cd.20b6d@apollo.HP.COM> Sender: root@apollo.HP.COM Reply-To: vinoski@apollo.HP.COM (Stephen Vinoski) Followup-To: comp.lang.c Organization: Hewlett-Packard Apollo Division - Chelmsford, MA Lines: 36 In article <519416cd.20b6d@apollo.HP.COM> vinoski@apollo.HP.COM (Stephen Vinoski) writes: >In article <28302040.69ED@deneva.sdd.trw.com> knurlin@spf.trw.com (Scott Karlin) writes: >>I am looking for a clarification on the ANSI-C token merging >>operator (##). According to H&S: "After *all* [emphasis mine] >>macro replacements have been done, the two tokens surrounding >>any ## operator are combined into a single token." I interpret >>this to mean that: >> >>#define INDEX 0 >>#define FN_NAME(x) name ## x >>void FN_NAME(INDEX) () { printf("Hello\n"); } > >I had a problem with token pasting similar to yours. A compiler >writer said that the problem was caused by the fact that I was >attempting to paste arbitrary text with macro parameters; he said that >token pasting is only meant to work on macro parameters. > >The ANSI C standard appears to agree with him; I believe it is section >3.8.3.3 (I don't have the standard handy) that says that ## causes >macro parameters to be pasted together. If I have misinterpreted the >standard, I'm sure I will hear about it. :-) Well, what do you know - I *did* misinterpret the standard. Sigh. Section 3.8.3.3 states that preprocessor tokens can be pasted together. The problem knurlin@spf.trw.com has is caused by the fact that token pasting occurs before the result is rescanned for further macro replacement. Thanks to steven@pacific.csl.uiuc.edu (Steven Parkes) for setting me straight on this one. I hereby promise not to quote the standard from memory again. -steve | Steve Vinoski (508)256-0176 x5904 | Internet: vinoski@apollo.hp.com | | HP Apollo Division, Chelmsford, MA 01824 | UUCP: ...!apollo!vinoski |