In VC++ .Net, The What does the Clr/Safe (/clr:safe
) and Clr/Pure (/clr:pure
) means?

- 78,363
- 46
- 261
- 468

- 41
- 2
-
Additional information from DUMPBIN's documentation: "The /clr:pure and /clr:safe compiler options are deprecated in Visual Studio 2015 and unsupported in Visual Studio 2017 and later. Code that must be "pure" or "safe" should be ported to C#." - https://learn.microsoft.com/en-us/cpp/build/reference/clrheader?view=msvc-170 – sɐunıɔןɐqɐp Jun 26 '23 at 07:45
2 Answers
From the doc:
/clr:pure Produces a Microsoft Intermediate Language (MSIL)-only output file that has no native executable code. However, it can contain native types compiled to MSIL.
/clr:safe Produces an MSIL-only (no native executable code), verifiable output file. /clr:safe enables verification diagnostics (PEVerify Tool (Peverify.exe)).

- 1,023,142
- 271
- 3,287
- 2,928
-
Does this prevent me from accessing DirectX or win32 code from within my c++ cli assembly? – Gusdor Feb 07 '11 at 09:21
-
I would also like to know if these are just type-checking or if these place a flag in the header that identifies them as pure or safe? – Evan Carroll Dec 17 '17 at 07:17
I don't think that's enough information. It seemed from the other answer that it was just type checking. It seems from this doc that it's a lot more than that.
When
/clr
(not/clr:pure
or/clr:safe
) is used and__clrcall
is not used, taking the address of a function always returns the address of the native entry point function. When__clrcall
is used, the native entry point function is not created, so you get the address of the managed function, not an entry point thunk function. For more information, see Double Thunking.
/clr
(Common Language Runtime Compilation) implies that all functions and function pointers are__clrcall
and the compiler will not permit a function inside the compiland to be marked anything other than__clrcall
. When /clr:pure is used,__clrcall
can only be specified on function pointers and external declarations.

- 1
- 1

- 78,363
- 46
- 261
- 468