How can I add more than one inline assembly instruction in a macro with VC++?
Why does the following macro compile with 1 inline assembly instruction but not with 2?
This code compiles OK:
#define foo(x,output,ctx) {\
    __asm\
    {\
        mov eax, 0xCAFEBEE1\
    }\
} 
but this code produces an err开发者_运维问答or:
#define foo(x,output,ctx) {\
    __asm\
    {\
        mov eax, 0xCAFEBEE1\
        add eax, 5\
    }\
}
Try this:
#define foo(x,output,ctx) {\
    __asm mov eax, 0xCAFEBEE1 \
    __asm add eax, 5\
}
Whenever you have a problem with the pre-processor, be sure to use Project + Properties, C/C++, Preprocessor, Preprocess to a file = Yes. Build and you'll find a .i file in the build directory. Which shows this on your snippet:
int wmain(int argc, _TCHAR* argv[])
{
    { __asm { mov eax, 0xCAFEBEE1 add eax, 5 }};
    return 0;
}
Now it is obvious, there are no line endings on the macro lines. Curse at the preprocessor a bit to make you feel better. Then one __asm per line to fix.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论