Concatenating with a compile-time definition in "ANSI" CPP
Fred Smith
fredex at cg-atla.UUCP
Wed Oct 4 22:48:35 AEST 1989
In article <17975 at pasteur.Berkeley.EDU> hunt at ernie.Berkeley.EDU.UUCP (Jim Hunt) writes:
>In article <11212 at smoke.BRL.MIL> gwyn writes:
>>In <17936 at pasteur.Berkeley.EDU> hunt at ernie.Berkeley.EDU.UUCP (Jim Hunt) writes:
>>>You can do this in non ANSI environments (at least Sun) with
>>>#define MyInit(arg) arg/**/Init
> <stuff deleted>
>Question, what do ansi compilers do with that? They don't HAVE
>to have a pre-processor, but who doesn't, and if there is a PP,
>which eliminates /*comments*/, what token does it put in to
>identify where comments were? Would you complicate your yacc by
>allowing comment tokens everywhere? NO! I guess the solution
>would be in the lex phase, but I still think you are fighting
>hard to eliminate a rather harmless artifact of the fact that
>you use a preprocessor.
>
Well, Microsoft C may not be a flawless ANSI implementation, but it is somewhere
in the ballpark, and when you give it that construct it thinks you are talking
about two different items named arg, and Init. This is reasonable, and I think
correct behavior. If one reads K&R, or ANSI standard, one will see that they both
state that comments in the source are replaced with WHITE SPACE in the preprocessor
phase of translation. Clearly, if comments become whtie space, then this ugly
hack (i.e., "/**/", which is, after all, a comment!!) will not result in arg and
Init being pasted together!!!!
This usage, then, is clearly an aberration on what the language was originally
intended and documented to be. Not to say that it isn't useful, though, which is,
I am sure, why the standard committee chose to specify an official, blessed,
way to doing it.
Fred Smith
More information about the Comp.lang.c
mailing list