I have had a problem with the new Visual C ++ in VS 2010.
I've found a header with the following:
#define STC (y) #y #define STR (y) STC (\ y) # Define NNN (y) 0 ## y #define NUM (Y) NN (Y)
This means that you can stay certain
#define TOKEN x5A
And after that you may have a token in the form of a number or as a string:
NUM (TOKEN) - & Gt; 0x5 A STR (Token) - & gt; This is the expected behavior under the replacement rules of macros logic and so far it has worked well with GCC, OpenWhatcom, PelcC (LCC), Digital Mars and others. Visual C ++ in the VS-2008 Express Today, I came back to the library with the VS 2010 Express to know that it does not work anymore! I have to use the new version:
NUM (TOKEN) - & gt; 0x5 A STR (Token) - & gt; It appears that the new preprocessor treats any action sequence as an action sequence even within a macro body, which is just an invisibility in the form of escape sequences. It means in verbal strings. I suspect that this is a gray area of the ANSI standard, but if the basic behavior is mandatory by the standard, then MS VC + 100% does not conform to the ANSI C, so I think I have a MS Compiler Must have to live with the new behavior.
Given that have any suggestions about re-implementing the original macro behavior with VS02010? Edit: NUM ()
Macro
Edit: Possible Solutions
I think I have found a way to do this:
#define STC (y) #y #if Defined (_MSC_VER) & amp; Amp; (_MSC_VER & gt; = 1600) # Defined STC (X, Y) STC (Ex ##Y) # Defined STR (Y) STA (\, Y) # Als # Define STR (Y) STC (\ y) # ADIF #define NNN (y) ## y #define NUM (y) NNN (y)
Now I'm getting:
#token x2e NUM (token) - & gt; 0x2E STR (token) - & gt; "GSE"
Of course, the GCC complains about a backslash being included in the literal ( \ ## x2E
) because the result is not a valid preprocessor symbol , But MS is happy, so #ifdef
.
I would love to hear that someone has a better solution!
You rely on some strange non-standard behaviors of the compiler.
Your NUM
macro is typed incorrectly This should never work, neither in the old nor in the new version of the compiler. When you do NUM (TOKEN)
, the macro extension will not result in 0TOKEN
and 0x5A
in a standard-compatible compiler. For the purpose of creating your NUM
macro function, you have to implement it in two-level fashion:
#define NUM_ (y) 0 ## y #define NUM ( Y) y (y)
The only reason that "work" for you is yet another mess in the compiler.
I'm not sure what is happening with the STR
case. The compiler is actually complaining about an unfamiliar escape sequence, there should be a bug in the compiler.
Comments
Post a Comment