Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!aero-c!gumby.dsd.trw.com!deneva!knurlin From: knurlin@spf.trw.com (Scott Karlin) Newsgroups: comp.lang.c Subject: Question on ANSI ## pre-processor operator. Message-ID: <28302040.69ED@deneva.sdd.trw.com> Date: 14 May 91 17:37:03 GMT Sender: news@deneva.sdd.trw.com Organization: TRW Data Systems Center, Redondo Beach, CA Lines: 71 Originator: knurlin@deneb 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"); } Should expand to: void name ## 0 () { printf("Hello\n"); } And then: void name0 () { printf("Hello\n"); } Which is what I want. However, two different ANSI (they say) compilers are not defining a function called "name0". Here is the actual code I used: /* ** example.c */ #include #define PID 0 /* ** Token merging macro... */ #define FN_NAME(x) funct ## x /* ** Function prototypes... */ void main(void); void funct0(void); /* ** Simple main function. Nothing tricky here... */ void main() { funct0(); return; } /* ** I believe that this should get expanded by the pre-processor to ** funct0 () Note that I have intentionally placed a space between ** the macro "call" and the empty function parameter list. */ void FN_NAME(PID) () { printf("Hello, world.\n"); return; } Any information on the correct interpretation would be most welcome. -- Scott Karlin Internet: knurlin@spf.trw.com -- TRW Data Systems Center UUCP: ...!uunet!knurlin@spf.trw.com -- One Space Park, O2-1761 Phone: (213) 812-7335 -- Redondo Beach, CA 90278-1071 FAX: (213) 812-8800