Export (0) Print
Expand All
Expand Minimize

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)
{
   try
   {
      int __pin* p = &pG->m;
      // manually unpin, ignore warning
      // p = 0;
      throw new Exception;
   }
   catch(Exception*)
   {
   }
}   // C4823

int main()
{
   f( new G );
}
Show:
© 2014 Microsoft