I ran into another issue dealing with reinterpret on bits (primitive) types.
julia> primitive type Foo 64 end
julia> struct Bar ; data::NTuple{8,UInt8} ; end
julia> reinterpret(Foo, 0x123456789abcdef0)
Foo(0x123456789abcdef0)julia> reinterpret(Bar, 0x123456789abcdef0)
ERROR: bitcast: target type not a leaf primitive type
Stacktrace:
[1] reinterpret(::Type{Bar}, ::UInt64) at ./essentials.jl:340
[2] top-level scopejulia> reinterpret(NTuple{8,UInt8}, 0x123456789abcdef0)
ERROR: bitcast: target type not a leaf primitive type
Stacktrace:
[1] reinterpret(::Type{NTuple{8,UInt8}}, ::UInt64) at ./essentials.jl:340
[2] top-level scopejulia> reinterpret(NTuple{8,UInt8}, [0x123456789abcdef0])
1-element reinterpret(NTuple{8,UInt8}, ::Array{UInt64,1}):
(0xf0, 0xde, 0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12)
I wanted to know what is the rationale for allowing one, but not the other?
It would be very useful to be able to take an instance of a primitive bits type (or an immutable struct) and reinterpret it as another primitive or immutable struct type of the same size, without having the performance overhead of having to place it into a vector just to be able to do the reinterpreting.