Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!dciem!nrcaer!cognos!geovision!alastair From: alastair@geovision.UUCP (Alastair Mayer) Newsgroups: comp.lang.c Subject: Re: Portability and /**/ Message-ID: <118@geovision.UUCP> Date: Tue, 28-Jul-87 16:03:46 EDT Article-I.D.: geovisio.118 Posted: Tue Jul 28 16:03:46 1987 Date-Received: Fri, 31-Jul-87 01:20:10 EDT References: <949@oakhill.UUCP> <23575@sun.uucp> <4983@prls.UUCP> Reply-To: alastair@geovision.UUCP (Alastair Mayer) Organization: Geovision Corporation, Ottawa, Canada Lines: 44 Summary: Sometimes useful, cpp does it, different syntax between SysV and BSD In article <4983@prls.UUCP> gardner@prls.UUCP (Robert Gardner) writes: >We recently received a large amount of code written for our >Unix VAX in C. It's device driver routines make extensive use >of an interesting construct -- a rather large number of #defines >are of the form: >#define a(n) a/**/n >so that, for instance, a(2) expands to a2. > [...] In pursuing this (out of curiosity), I >found that the Ultrix VAX c compiler compiles the program > main() > { > int n2=2; > printf("%d\n",n/*comment*/2); > } >and prints out '2' when executed. This suggests that the pre-processor >simply removes comments, rather than replacing them with white space. >My Lightspeed C compiler at home will not compile the above program. >Any comments on portability? > >Robert Gardner You are right, the C pre-processor does (normally) strip out the comments. However, the exact semantics depend on the particular version (BSD or SYSV) of 'cpp'. There *are* uses for this -- you note one. The C++ compiler (which also uses 'cpp') uses a similar mechanism to allow definition of generic classes. The file has code something like: #ifdef BSD /* BSD way */ #define name2(a,b) a\ b #else /* System V way */ #define name2(a,b) a/**/b #endif You might try the former method with your Lightspeed C (never having used it, I dunno if it'll work either). As to portability, if you *must* catenate tokens like this, then #define a macro to do it such as the above. -- Alastair JW Mayer BIX: al UUCP: ...!utzoo!dciem!nrcaer!cognos!geovision!alastair (Why do they call it a signature file if I can't actually *sign* anything?)