managed, unmanaged
Visual Studio .NET 2003
#pragma managed #pragma unmanaged
The /clr compiler option provides module-level control for compiling functions either as managed or unmanaged. The managed and unmanaged pragmas enable function-level control for compiling functions 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 managed by default when /clr is used. The compiler ignores the managed and unmanaged pragmas if /clr is not used in the compilation.
Example
// pragma_directives_managed_unmanaged.cpp
// compile with: /clr
#using <mscorlib.dll>
#include <stdio.h>
// func1 is managed
void func1(void)
{
System::Console::WriteLine("In managed function.\n");
}
#pragma unmanaged
// func2 is unmanaged
void func2(void)
{
printf("In unmanaged function.\n");
}
#pragma managed
// main is managed
int main()
{
func1();
func2();
}
Output
In managed function. In unmanaged function.