I got the 2 following definition that compile (and work) just fine using XCode LLVM-GCC compiler:
#define SAVE_STACK(v)__asm { mov v, ESP }
#define RESTORE_STACK __asm {sub ESP, s }
However when I change the compiler to Apple LLVM I got the following error:
Expected '(' after 'asm'
I replace the {} with () but that doesn’t do the trick, I google on that error couldn’t find anything useful… anyone?
The
__asm {...}style of inline assembly is non-standard and not supported by clang. Instead C++ specifies inline assembly syntax asasm("..."), note the quotes. Also clang uses AT&T assembly syntax so the macros would need to be rewritten to be safe.However, some work has been going on to improve support for Microsoft’s non-standard assembly syntax, and Intel style assembly along with it. There’s an option
-fenable-experimental-ms-inline-asmthat enables what’s been done so far, although I’m not sure when it was introduced or how good the support is in the version of clang you’re using. A simple attempt with the code you show seems to work with a recent version of clang from the SVN trunk.clang++ tmp.cpp -fms-extensions -fenable-experimental-ms-inline-asm -S -o -
And the command clang++ tmp.cpp -fms-extensions -fenable-experimental-ms-inline-asm produces an executable that runs.
It does still produce warnings like the following though.