Compiler Error C2441

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Compiler Error C2441.

variable' : a symbol declared with __declspec(process) must be const in /clr:pure mode

By default, variables are per application domain under /clr:pure. A variable marked __declspec(process) under /clr:pure is prone to errors if modified in one application domain and read in another.

Therefore, the compiler enforces per process variables be const under /clr:pure, making them read only in all application domains.

For more information, see process and /clr (Common Language Runtime Compilation).

The following sample generates C2441.

// C2441.cpp  
// compile with: /clr:pure /c  
__declspec(process) int i;   // C2441  
__declspec(process) const int j = 0;   // OK  

Show: