managed, unmanaged

摘自MSDNhttp://msdn.microsoft.com/en-us/library/0adb9zxe%28VS.80%29.aspx

 

 

托管以及不托管MSDN说明

 

Enable function-level control for compiling functions as managed or unmanaged.

#pragma managed
#pragma unmanaged
#pragma managed([push,] on | off)
#pragma managed(pop)

The /clr compiler option provides module-level control for compiling functions either as managed or unmanaged.

An unmanaged function will be compiled for the native platform, and execution of that portion of the program will be passed to the native platform by the common language runtime.

Functions are compiled as managed by default when /clr is used.

Use the following guidelines when applying these pragmas:

  • Add the pragma preceding a function but not within a function body.

  • Add the pragma after #include statements (do not use these pragmas before #include statements).

The compiler ignores the managed and unmanaged pragmas if /clr is not used in the compilation.

When a template function is instantiated, the pragma state at the time of definition for the template determines if it is managed or unmanaged.

For more information, see Initialization of Mixed Assemblies .

// pragma_directives_managed_unmanaged.cpp
// compile with: /clr
#include <stdio.h>

// func1 is managed
void func1() {
System::Console::WriteLine("In managed function.");
}

// #pragma unmanaged
// push managed state on to stack and set unmanaged state
#pragma managed(push, off)

// func2 is unmanaged
void func2() {
printf("In unmanaged function./n");
}

// #pragma managed
#pragma managed(pop)

// main is managed
int main() {
func1();
func2();
}
Output
In managed function.
In unmanaged function.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值