This documentation is archived and is not being maintained.

Compiler Warning (level 3) C4823

'function' uses pinning pointers but unwind semantics are not enabled. Consider using /EHsc

To unpin a gc object pointed to by a pinning pointer declared in a block scope, the compiler simulates the behavior of destructors of local classes, "pretending" the pinning pointer has a destructor that nullifies the pointer. To enable a call to a destructor after throwing an exception, you must enable object unwinding, which you can do by using /EHsc.

You can also manually unpin the object and ignore the warning, as shown below.

The following sample generates C4823:

// C4823.cpp
// compile with: /clr /W3
#using <mscorlib.dll>
using namespace System;

__gc struct G
   int m;

void f(G* pG)
      int __pin* p = &pG->m;
      // manually unpin, ignore warning
      // p = 0;
      throw new Exception;
}   // C4823

int main()
   f( new G );