Export (0) Print
Expand All
2 out of 2 rated this helpful - Rate this topic

managed, unmanaged

#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.


// 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()


In managed function.

In unmanaged function.

See Also

Pragma Directives

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.