What does the next line mean ??? #pragma managed(push, off)
1 answer
This is necessary when compiling source code in C ++ / CLI.
C ++ / CLI is a .NET extension of the C ++ language. When executing C ++ / CLI code, two runtime libraries are involved: native and managed. Some rules for these runtime libraries are different (for example, the creation time of static objects). Typically, functions are compiled in CLR mode, but you can explicitly specify native, C ++ standard-compatible mode using #pragma managed .
When compiled in the native mode, this function “communicates” with the native runtime, and when compiled in the managed mode, in the managed mode. In particular, the native function cannot use managed types (for example, System::String^ ). #pragma managed(push, off) actually means “remember the current state in the state stack, and set the native mode”. At the end of the native section usually follows #pragma managed(pop) , which restores the previous state from the stack.
Regarding the language differences in the controlled and unmanaged modes, the documentation has a complete list. In particular, inline assembler and vprintf do not work.
Also, managed functions can be detected in a module using reflection, as opposed to native ones.
It is better to include standard header files in the native mode, since the corresponding libraries were also compiled in the native mode.
- What is the difference between the native and CLR modes and why go from one to another? - user251082
- @ user251082: Added in response. - VladD
- onenative is a compilation into the machine code of a specific processor, and managed into a virtual machine code (for example .net or Dalvik). Machine code is twice as efficient, but not portable to other CPUs - Pavel Gridin
- one@PavelGridin: I don’t think everything is that simple. Address arithmetic and
reinterpret_castcan hardly be expressed in MSIL. - VladD