Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 1.42 KB

compiler-warning-level-3-c4398.md

File metadata and controls

34 lines (25 loc) · 1.42 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: Compiler Warning (level 3) C4398
Compiler Warning (level 3) C4398
11/04/2016
C4398
C4398
b6221432-9fed-4272-a547-a73f587904e6

Compiler Warning (level 3) C4398

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

Remarks

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 explicitly marking the variable __declspec(appdomain). In versions of Visual Studio before Visual Studio 2017, you can resolve this warning by compiling with /clr:pure, which makes global variables per appdomain by default. The /clr:pure compiler option is deprecated in Visual Studio 2015 and unsupported in Visual Studio 2017.

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

Example

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