jagardner@watmath.waterloo.edu (Jim Gardner) (03/06/88)
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)