<div dir="ltr">Yeah, that makes sense. If your C API requires an intptr_t, you can&#39;t solve that problem by adding more functions to UnsafePointer. I&#39;ll go ahead and start a discussion over on swift-evolution. Thanks!</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 8, 2015 at 3:07 PM, Jordan Rose <span dir="ltr">&lt;<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>The one I can think of is &quot;sometimes a C API only lets you pass data as an Int (intptr_t) or as an UnsafeMutablePointer (void *), and you have the other kind of data&quot;. That said, it does seem to be sort of a niche use case.</div><div><br></div><div>Jordan</div><br><div><blockquote type="cite"><div><div class="h5"><div>On Dec 8, 2015, at 7:59, Michael Buckley via swift-dev &lt;<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>&gt; wrote:</div><br></div></div><div><div><div class="h5"><div dir="ltr">I&#39;m looking for a good starter project, so normally I would be interested in taking this, but I&#39;m not sure I can think of a good motivation for it. UnsafePointer&#39;s advanceBy and distanceTo functions take care of pointer arithmetic more safely than converting to int would, and the debugDescription property can get you the address for debugging purposes.<div><br></div><div>Considering that everything that goes through the swift-evolution process needs to have a motivation, is there a use case for this that I&#39;m not thinking of?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 7, 2015 at 4:45 PM, Dmitri Gribenko via swift-dev <span dir="ltr">&lt;<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everyone,<br>
<br>
The standard library has bitPattern initializers on pointers. But we<br>
are missing initializers to create integers from pointers.<br>
<br>
Someone needs to propose these APIs, walk them through<br>
swift-evolution, write a patch for the library and add tests.<br>
<br>
extension UInt {<br>
  init&lt;T&gt;(bitPattern: UnsafePointer&lt;T&gt;) {<br>
    self = UInt(Builtin.ptrtoint_Word(bitPattern._rawValue))<br>
  }<br>
<br>
  init&lt;T&gt;(bitPattern: UnsafeMutablePointer&lt;T&gt;) {<br>
    self = UInt(Builtin.ptrtoint_Word(bitPattern._rawValue))<br>
  }<br>
}<br>
<br>
extension Int {<br>
  init&lt;T&gt;(bitPattern: UnsafePointer&lt;T&gt;) {<br>
    self = Int(Builtin.ptrtoint_Word(bitPattern._rawValue))<br>
  }<br>
<br>
  init&lt;T&gt;(bitPattern: UnsafeMutablePointer&lt;T&gt;) {<br>
    self = Int(Builtin.ptrtoint_Word(bitPattern._rawValue))<br>
  }<br>
}<br>
<br>
<a href="https://bugs.swift.org/browse/SR-131" rel="noreferrer" target="_blank">https://bugs.swift.org/browse/SR-131</a><br>
<span><font color="#888888"><br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf(&quot;%d\n&quot;,i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>&gt;*/<br>
_______________________________________________<br>
swift-dev mailing list<br>
<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-dev</a><br>
</font></span></blockquote></div><br></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=f6VunEbxOyO0-2FacKqVTeu6pGEEellWH1YmuP-2Bt5lLhMRo-2FnuAADF9px-2BNFFGXVy-2BEVfNUZR7G-2B6Z0PbtBtbY-2ByPNROo1OvH76O0xMFURRLT70jA6lnMfP8Bf2RCBUvIa-2B41LUOjezROJTLEmWpHJOSrLAQErL5b0Hq7a0ejOxpz9ICc-2FuABGaHBSg-2BGl83biILlry-2Bs3P8wx7SZzDdBgwAeZ-2B5tj8oap0VPsvUsM-2F6w-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
_______________________________________________<span class=""><br>swift-dev mailing list<br><a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-dev" target="_blank">https://lists.swift.org/mailman/listinfo/swift-dev</a><br></span></div></blockquote></div><br></div></blockquote></div><br></div>