This documentation is archived and is not being maintained.

Compiler Error C3834

Error Message

illegal explicit cast to a pinning pointer; use a pinned local variable instead

Explicit casts to a pinned pointer are not allowed.


The following sample generates C3834.

// C3834.cpp
// compile with: /clr
int main() {
   int x = 33;

   pin_ptr<int> p = safe_cast<pin_ptr<int> >(&x);   // C3834
   pin_ptr<int> p2 = &x;   // OK

The following sample generates C3834.

// C3834_b.cpp
// compile with: /clr:oldSyntax
using namespace System;

int main() {
   const __wchar_t * pS = reinterpret_cast<const __wchar_t __pin*>(S"hello");   // C3834

   // OK 
   // declare a pinning variable
   String __pin* ppin = S"Hello";

   // cast pinning variable to unmanaged type
   const __wchar_t * pS2 = reinterpret_cast<__wchar_t*>(ppin);   

   pS2 += 6;