<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="">When writing high-performance code, it is fairly common to check the alignment of pointers so that initial elements can be processed until some suitable alignment is reached to use a faster implementation, or to verify that a fast algorithm can be used.</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Dec 8, 2015, at 10:59 AM, 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=pngPxwQ4BiP5IDU2rQC6TcjbiXVR4eqjpuzmzac21kjdDjX8OUqNSR5K5Ti12EqnUGGIQy0jQddi-2F5GxvDpfM0hVk04p-2Fk1711hXX-2Bnfjni86We2gg2LhjdGx5j5kLW-2FQ8ZwCSAwJULIVAFKKlDdBBZ6oqaz1bONw9hbWu573yory6wFNBMOBwTtJY6wAjhGO0u4S3RoP23-2FAva-2BkHc78YcKg-2F4LZsyQAkVyLF3cDPs-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>