title: String value to UnsafePointer<UInt8> function parameter behavior
body: <p>I found the following code compiles and works:</p>
  
  <pre><code>func foo(p:UnsafePointer&lt;UInt8&gt;) {
      var p = p
      for p; p.memory != 0; p++ {
          print(String(format:"%2X", p.memory))
      }
  }
  
  let str:String = "今日"
  foo(str)
  </code></pre>
  
  <p>This prints <code>E4BB8AE697A5</code> and that is a valid UTF8 representation of <code>今日</code></p>
  
  <p>As far as I know, this is undocumented behavior. from <a href="https://developer.apple.com/library/ios/documentation/swift/conceptual/buildingcocoaapps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-XID_15">the document:</a></p>
  
  <blockquote>
    <p>When a function is declared as taking a UnsafePointer argument, it can accept any of the following:</p>
    
    <ul>
    <li>nil, which is passed as a null pointer</li>
    <li>An UnsafePointer, UnsafeMutablePointer, or AutoreleasingUnsafeMutablePointer value, which is converted to UnsafePointer if necessary</li>
    <li>An in-out expression whose operand is an lvalue of type Type, which is passed as the address of the lvalue</li>
    <li>A [Type] value, which is passed as a pointer to the start of the array, and lifetime-extended for the duration of the call</li>
    </ul>
  </blockquote>
  
  <p>In this case, <code>str</code> is non of them.</p>
  
  <p>Am I missing something?</p>
  
  <hr>
  
  <p><strong>ADDED:</strong></p>
  
  <p>And it doesn't work if the parameter type is <code>UnsafePointer&lt;UInt16&gt;</code></p>
  
  <pre><code>func foo(p:UnsafePointer&lt;UInt16&gt;) {
      var p = p
      for p; p.memory != 0; p++ {
          print(String(format:"%4X", p.memory))
      }
  }
  let str:String = "今日"
  foo(str)
  //  ^ 'String' is not convertible to 'UnsafePointer&lt;UInt16&gt;'
  </code></pre>
  
  <p>Even though the internal <code>String</code> representation is UTF16</p>
  
  <pre><code>let str = "今日"
  var p = UnsafePointer&lt;UInt16&gt;(str._core._baseAddress)
  for p; p.memory != 0; p++ {
      print(String(format:"%4X", p.memory)) // prints 4ECA65E5 which is UTF16 今日
  }
  </code></pre>