# Reinterpret on primitive type

**URL:** https://discourse.julialang.org/t/reinterpret-on-primitive-type/7187
**Category:** General Usage
**Created:** [November 20, 2017, 1:56pm UTC](https://discourse.julialang.org/t/reinterpret-on-primitive-type/7187 "2017-11-20T13:56:23Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)
#### Post date: [November 20, 2017, 1:56pm UTC](https://discourse.julialang.org/t/reinterpret-on-primitive-type/7187/1 "2017-11-20T13:56:24Z")

</div>

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 scope
> 
> julia\> 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 scope
> 
> julia\> 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.
