Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!apple!agate!ucbvax!bloom-beacon!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.questions Subject: Re: Preprocessor Usage Question Message-ID: <1991Apr25.234340.22311@athena.mit.edu> Date: 25 Apr 91 23:43:40 GMT References: <1991Apr25.193750.16702@ssd.kodak.com> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 55 Many pre-ANSI-C preprocessors will let you use /**/ to do concatenation as Gary Weimer has described. Some ANSI-C preprocessors will let you do it too, but it's the WRONG way to do it with an ANSI-C preprocessor; under ANSI C, you should use the ## macro operator. I took the following source file: #define R1(x) a_/**/x #define R2(x) a_##x #define R3 a_ R1(func1)(args); R2(func1)(args); R3/**/func1(args); R3##func1(args); And fed it into 4.3BSD's preprocessor, and got out this (blank lines and # line number directives deleted): a_func1(args); a_##func1(args); a_func1(args); a_##func1(args); pit-manager% cc -E -Hnocpp test.c So, under 4.3BSD, the /**/ trick works, and ANSI C's ## doesn't. Then, I took the same file and fed it into High C's internal ANSI-C preprocessor, which resulted in: a_ func1 (args); a_func1 (args); a_ func1(args); a_##func1(args); Note first of all that the /**/ DIDN'T work, because extra blank space was left where the /**/ appeared. This is perfectly permissible according to the ANSI C specification. The ## operator worked, but only when it was used inside a macro, since that's when it's supposed to work. I guess the summary of all this is that something like this #ifdef __STDC__ #define RADIO(x) a_##x #else #define RADIO(x) a_/**/x #endif is the best you can do. -- Jonathan Kamens USnail: MIT Project Athena 11 Ashford Terrace jik@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710