C++/CLI with Pure Mode?
I have read in 开发者_开发问答Foundations of C++ CLI
the following:
If you try to compile a native C++ application with /clr:pure, it will work only if the code being compiled has no constructs that generate machine-specific code. You can, however, link with native libraries.
What is meant by "constructs that generate machine-specific code
" ? Example?
Also the book says that this mode is not verifiably safe, so we can use pointers for example, now i am confusing in how can say that the compiler will produce pure MSIL code and also we can use pointers! What i know is that, the pointer is somehow native concept! how it will be made as pure MSIL!?
MSIL is quite powerful, it has no trouble with standard compliant C++03 code. The only "constructs" I know of that it cannot deal with is the __fastcall calling convention, r-value references as implemented in the C++0x additions in VS2010 and obvious machine specific extensions like the __asm keyword (inline assembly) and intrinsics.
Most any native C++ you compile with /clr in effect will use pointers, either explicitly or compiler-generated to implement things like C++ classes and references. MSIL has no trouble with it but that code is not verifiable, any MSIL that uses pointers is rejected by the verifier. This is not necessarily a problem, lots of code runs in full-trust. You'll only get in trouble when you try to run it on sandboxed execution environments, like a browser, a phone or a game console. Or when your customer has a nervous system administrator.
Using /clr:pure is otherwise pretty useless. The point of using C++/CLI is for its great support for interop with native code. Compiling native code to MSIL is largely a waste, the JIT optimizer can't do as effective a job as the native code optimizer.
精彩评论