title: How to to assign the address of a local swift variable to an UnsafeMutablePointer
body: <p>Suppose I have a variable in Swift like</p>
  
  <pre><code>var i: CInt = 123;
  </code></pre>
  
  <p>How can I get an <code>UnsafeMutablePointer&lt;CInt&gt;</code> to point to the address of <code>i</code>?</p>
  
  <p>I know I can pass the address of this variable to a C function <code>void f(int *i)</code> by calling</p>
  
  <pre><code>f(&amp;i);
  </code></pre>
  
  <p>I also know that a C pointer can be represented in swift as  <code>UnsafeMutablePointer</code>. So the question is how can I assign the address of <code>i</code> to such an <code>UnsafeMutablePointer</code>. I would have expected that something like </p>
  
  <pre><code>var p: UnsafeMutablePointer&lt;CInt&gt; = &amp;i;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>var p = UnsafeMutablePointer&lt;CInt&gt;(&amp;i);
  </code></pre>
  
  <p>should work, but it doesn't. I guess I could write a C library providing the following function</p>
  
  <pre><code>int *noop(int *p){ return p;}
  </code></pre>
  
  <p>which could be used in Swift like</p>
  
  <pre><code>var p = noop(&amp;i);
  </code></pre>
  
  <p>but I haven't tried it and it can't be the correct solution. There must be something simpler. </p>
  
  <hr>
  
  <p>And please don't ask why I want to do this. Its more like an academic question to understand the designs of Swift and C interoperability. </p>