<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">The one I can think of is "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". That said, it does seem to be sort of a niche use case.</div><div class=""><br class=""></div><div class="">Jordan</div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 8, 2015, at 7:59, Michael Buckley via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I'm looking for a good starter project, so normally I would be interested in taking this, but I'm not sure I can think of a good motivation for it. UnsafePointer'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 class=""><br class=""></div><div class="">Considering that everything that goes through the swift-evolution process needs to have a motivation, is there a use case for this that I'm not thinking of?</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Dec 7, 2015 at 4:45 PM, Dmitri Gribenko via swift-dev <span dir="ltr" class="">&lt;<a href="mailto:swift-dev@swift.org" target="_blank" class="">swift-dev@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi everyone,<br class="">
<br class="">
The standard library has bitPattern initializers on pointers. But we<br class="">
are missing initializers to create integers from pointers.<br class="">
<br class="">
Someone needs to propose these APIs, walk them through<br class="">
swift-evolution, write a patch for the library and add tests.<br class="">
<br class="">
extension UInt {<br class="">
&nbsp; init&lt;T&gt;(bitPattern: UnsafePointer&lt;T&gt;) {<br class="">
&nbsp; &nbsp; self = UInt(Builtin.ptrtoint_Word(bitPattern._rawValue))<br class="">
&nbsp; }<br class="">
<br class="">
&nbsp; init&lt;T&gt;(bitPattern: UnsafeMutablePointer&lt;T&gt;) {<br class="">
&nbsp; &nbsp; self = UInt(Builtin.ptrtoint_Word(bitPattern._rawValue))<br class="">
&nbsp; }<br class="">
}<br class="">
<br class="">
extension Int {<br class="">
&nbsp; init&lt;T&gt;(bitPattern: UnsafePointer&lt;T&gt;) {<br class="">
&nbsp; &nbsp; self = Int(Builtin.ptrtoint_Word(bitPattern._rawValue))<br class="">
&nbsp; }<br class="">
<br class="">
&nbsp; init&lt;T&gt;(bitPattern: UnsafeMutablePointer&lt;T&gt;) {<br class="">
&nbsp; &nbsp; self = Int(Builtin.ptrtoint_Word(bitPattern._rawValue))<br class="">
&nbsp; }<br class="">
}<br class="">
<br class="">
<a href="https://bugs.swift.org/browse/SR-131" rel="noreferrer" target="_blank" class="">https://bugs.swift.org/browse/SR-131</a><br class="">
<span class="HOEnZb"><font color="#888888" class=""><br class="">
Dmitri<br class="">
<br class="">
--<br class="">
main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br class="">
(j){printf("%d\n",i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt;*/<br class="">
_______________________________________________<br class="">
swift-dev mailing list<br class="">
<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class="">
</font></span></blockquote></div><br class=""></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="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;" class="">
_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></blockquote></div><br class=""></body></html>