Compiler Warning (level 3) C4398
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Compiler Warning (level 3) C4398

Error Message

'variable' : per-process global object might not work correctly with multiple appdomains; consider using __declspec(appdomain)

A virtual function with __clrcall calling convention in a native type causes the creation of a per application domain vtable. Such a variable may not correct correctly when used in multiple application domains.

You can resolve this warning by compiling with /clr:pure, which makes global variables per appdomain by default, or by explicitly marking the variable __declspec(appdomain).

For more information, see appdomain and Application Domains and Visual C++.


The following sample generates C4398.

// C4398.cpp
// compile with: /clr /W3 /c
struct S {
   virtual void f( System::String ^ );   // String^ parameter makes function __clrcall

S glob_s;   // C4398
__declspec(appdomain) S glob_s2;   // OK
© 2016 Microsoft