<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="julia&gt; immutable Words32
         lo::UInt32
         hi::UInt32
       end
julia&gt; isbits(Words32)
true
julia&gt; a=UInt64(0x123456789abcdef0)
0x123456789abcdef0
julia&gt; b=reinterpret(Words32,a)
ERROR: reinterpret: expected bits type as first argument
 in reinterpret at essentials.jl:115"><pre class="notranslate"><code class="notranslate">julia&gt; immutable Words32
         lo::UInt32
         hi::UInt32
       end
julia&gt; isbits(Words32)
true
julia&gt; a=UInt64(0x123456789abcdef0)
0x123456789abcdef0
julia&gt; b=reinterpret(Words32,a)
ERROR: reinterpret: expected bits type as first argument
 in reinterpret at essentials.jl:115
</code></pre></div>
<p dir="auto">Besides the contradiction isbits() != bits type I think that would definitely be useful to be able to reinterpret immutables</p>
<p dir="auto">I was wondering, why this works:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="reinterpret(Float32, Int32(0))
@assert isbits(ImmutableType1) &amp;&amp; isbits(ImmutableType2) &amp;&amp; (sizeof(ImmutableType1) == sizeof(ImmutableType2)) 
reinterpret(ImmutableType1, Array(ImmutableType2, 42))"><pre class="notranslate"><span class="pl-c1">reinterpret</span>(Float32, <span class="pl-c1">Int32</span>(<span class="pl-c1">0</span>))
<span class="pl-c1">@assert</span> <span class="pl-c1">isbits</span>(ImmutableType1) <span class="pl-k">&amp;&amp;</span> <span class="pl-c1">isbits</span>(ImmutableType2) <span class="pl-k">&amp;&amp;</span> (<span class="pl-c1">sizeof</span>(ImmutableType1) <span class="pl-k">==</span> <span class="pl-c1">sizeof</span>(ImmutableType2)) 
<span class="pl-c1">reinterpret</span>(ImmutableType1, <span class="pl-c1">Array</span>(ImmutableType2, <span class="pl-c1">42</span>))</pre></div>
<p dir="auto">and this does not:</p>
<div class="highlight highlight-source-julia notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="reinterpret(ImmutableType1, ImmutableType2(...))"><pre class="notranslate"><span class="pl-c1">reinterpret</span>(ImmutableType1, <span class="pl-c1">ImmutableType2</span>(<span class="pl-k">...</span>))</pre></div>
<p dir="auto">This is convenient for converting different FixedSizeArrays with the same layout without copying anything.<br>
It's probably related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="38461766" data-permission-text="Title is private" data-url="https://github.com/JuliaLang/julia/issues/7697" data-hovercard-type="issue" data-hovercard-url="/JuliaLang/julia/issues/7697/hovercard" href="https://github.com/JuliaLang/julia/issues/7697">#7697</a>, which didn't get fully implemented?</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/vtjnash/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/vtjnash">@vtjnash</a> answered on Julia users:</p>
<blockquote>
<p dir="auto">That last one requires a different sequence of llvm instructions than the other examples (it's the difference between isbits and bitstype). Not hard, but likely unimplemented.</p>
</blockquote>
<p dir="auto">Is anyone willing to implement this, or give some pointers on how to implement it?</p>