title: Assigning UnsafeMutablePointer value to UnsafePointer without unsafeBitCast
body: <p>I am working with a C API that defines a structure with const char* and a function that returns a char* and am trying to find the best way to do the assignment.</p>
  
  <p>Is there a way to do this without using unsafeBitCast? If I don't put the cast then I get this error:</p>
  
  <pre><code>Cannot assign value of type 'UnsafeMutablePointer&lt;pchar&gt;' 
  (aka 'UnsafeMutablePointer&lt;UInt8&gt;') 
  to type 'UnsafePointer&lt;pchar&gt;!' 
  (aka 'ImplicitlyUnwrappedOptional&lt;UnsafePointer&lt;UInt8&gt;&gt;')
  </code></pre>
  
  <p>Also, will the initialization of pairPtr below using pair() allocate a pair struct on the stack to initialize the allocated pair on the heap because this seems inefficient for the case where the structure just has to be zero'd out.</p>
  
  <p>Here is sample code:</p>
  
  <p>C library header (minimized to demonstrate the problem):</p>
  
  <pre><code>#ifndef __PAIR_INCLUDE__
  #define __PAIR_INCLUDE__
  
  typedef unsigned char pchar;
  
  pchar*
  pstrdup(const pchar* str);
  
  typedef struct _pair {
      const pchar* left;
      const pchar* right;
  } pair;
  
  #endif // __PAIR_INCLUDE__
  </code></pre>
  
  <p>My Swift code:</p>
  
  <pre><code>import pair
  
  let leftVal = pstrdup("left")
  let rightVal = pstrdup("right")
  
  let pairPtr = UnsafeMutablePointer&lt;pair&gt;.allocate(capacity: 1)
  pairPtr.initialize(to: pair())
  
  // Seems like there should be a better way to handle this:
  pairPtr.pointee.left = unsafeBitCast(leftVal, to: UnsafePointer&lt;pchar&gt;.self)
  pairPtr.pointee.right = unsafeBitCast(rightVal, to: UnsafePointer&lt;pchar&gt;.self)
  </code></pre>
  
  <p>The C code:</p>
  
  <pre><code>#include "pair.h"
  #include &lt;string.h&gt;
  
  pchar*
  pstrdup(const pchar* str) {
      return strdup(str);
  }
  </code></pre>
  
  <p>The module definition:</p>
  
  <pre><code>module pair [extern_c] {
      header "pair.h"
      export *
  }
  </code></pre>