guy@sun.UUCP (04/29/86)
> Try this fix for system V cpp: > > #define name2(a,b) a/**/b > #define name3(a,b,c) a/**/b/**/c > > This works because the system V cpp strips the comments from the input. So do earlier versions of Reiser's "cpp"; this is the "canonical" way of concatenating two arguments to a macro, and is heavily used in 4BSD. It has, however, two problems: 1) If you run your code through "lint", it won't work - "cpp" is run by "lint" with the "-C" flag, which tells it not to strip comments (for obvious reasons). 2) It is not a guaranteed property of the C language, but a quirk of the implementation, so it will not work in general. -- Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.arpa
kwh@bentley.UUCP (KW Heuer) (04/30/86)
In article <3597@sun.uucp> sun!guy (Guy Harris) writes: >> #define name2(a,b) a/**/b >It has, however, two problems: > > 1) If you run your code through "lint", it won't work I tried this example with "cpp -C" and it worked fine. I'd guess that cpp strips all comments in preprocessor directives reg Cdless of "-C". > 2) It is not a guaranteed property of the C language, but a > quirk of the implementation, so it will not work in > general. Agreed. Any application that depends on being able to do this is treading on thin ice. Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint
rbm@sfsup.UUCP (R.B.Murray) (05/02/86)
> In article <3597@sun.uucp> sun!guy (Guy Harris) writes: > >> #define name2(a,b) a/**/b > >It has, however, two problems: > > > > 1) If you run your code through "lint", it won't work > > I tried this example with "cpp -C" and it worked fine. I'd guess that > cpp strips all comments in preprocessor directives regardless of "-C". > > > 2) It is not a guaranteed property of the C language, but a > > quirk of the implementation, so it will not work in > > general. > > Agreed. Any application that depends on being able to do this is treading > on thin ice. > > Karl W. Z. Heuer (ihnp4!bentley!kwh), The Walking Lint Agreed also. I also don't believe there is a standard and portable way to do this at the present time. However, the current draft of the ANSI C standard has an "offical" way to do this: #define name2(a,b) a##b The "##" is a (new) concatenation operator. Of course, this is only useful once a standard exists and everybody conforms to it. Also, ANSI may change their minds on the syntax of this feature. Rob Murray AT&T Summit, NJ