Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!gatech!mcnc!decvax!watmath!jagardner From: jagardner@watmath.waterloo.edu (Jim Gardner) Newsgroups: comp.lang.c Subject: ANSI CPP ## operator Message-ID: <17301@watmath.waterloo.edu> Date: 6 Mar 88 00:34:56 GMT References: <11879@brl-adm.ARPA> <2631@haddock.ISC.COM> <898@PT.CS.CMU.EDU> <290@alice.marlow.reuters.co.uk> Reply-To: jagardner@watmath.waterloo.edu Organization: U. of Waterloo, Ontario Lines: 29 Summary: was Re: macros with parameters in MSC 5.0 In article <290@alice.marlow.reuters.co.uk> fox@alice.marlow.reuters.co.uk (Paul Fox) writes: >ANSI gets around this via the '#' and '##' operators -- available within >the preprocessor phase only. As I read it > ... ># define CTRL(x) '##x##' & 037 > CTRL(A); > >gives: 'A' & 037 ## concatenates two preprocessor tokens. Is "'" guaranteed to be a valid pre-processor symbol? I don't think so, so the result is implementation defined. Similarly, if the result of ## is not a valid token, the result is implementation defined (or some other term, I forget, which means unpredictable results). So after the first "'##x" (or "x##'" if the implementation does it that way), the result is not a valid token, and the implementation might do something strange. An example of possible behaviour that I think conforms with the standard: the "'" is an invalid token, and is left as a special internal token. (i.e., same token type generated by an @) "'##x" doesn't form a valid token, so it is left as two tokens (invalid token and the x macro arg) then a similar thing happens with "x##'", resulting in three separate tokens. Another possibility is that the "'##x##'" is interpretted as a character constant which might result in an error or warning about too many chars in a char constant (actually, I think this is more likely, maybe even required by the ANSI standard). To see this in another light consider #define f(a) "##a##" f(hi there)