Friday 15 April 2011

Outputing backslash in a C++ macro -


Is macro possible to write in C ++, which will return the after extension backslash?

I am currently using a code:

  # SOME_ENUM (XX) \ xX (first value), \ xX (second value), \ xX (some Other value = 50) \ XX (OneMoreValue, = 100) \   

But I want to write a macro, which will generate the above code, so I want to be able to write:

  ENUM_BEGIN (name) // It should be output: # DEFINE SOME_ENUM (XX) \ ENUM (ONE) // It should be output: XX (ONE,) \ // ...   

but I'm not able to write a macro like ENUM_BEGIN Was it because it should finally expand to something with backslash, is it possible in C ++?

No, this is not possible. According to the translation phase 2, described in ISO / IEC 14882: 2011 (E), this will be § 2.2.1.

The example of each backslash character () is immediately removed after a new line character is removed, separating the physical source lines to create logical source lines. Only the last backslash on any physical source line will be eligible to be part of this kind of sacrifice. If, as a result, a character sequence that matches the syntax of a universal-character-name, is produced, behavior is undefined. A source file that is not blank and that does not end in a new-line character, or that ends immediately after a backslash character of such type of partition that ends in the character of a new line, processed it As if an additional new line line was added to the file.

What will be actually \\\ n (where \ n is physically in the source, not an escape) Will be considered as a \ character, followed by a line benzene, the remaining \ can be in a syntax error (there may be situations where it is legal , But I no longer see it in any way), and during the subsequent translation steps the line is not treated as benzene (line different There is only a step # 2).

No comments:

Post a Comment