digitalmars.D.learn - Why isn't int[] automatically convertible to long[]?
- Jack Stouffer (3/3) Sep 03 2015 pragma(msg, is(int[] : long[]));
- Adam D. Ruppe (11/14) Sep 03 2015 Think of the memory layout... if you implicitly casted, either
pragma(msg, is(int[] : long[]));
false
Why?
Sep 03 2015
On Thursday, 3 September 2015 at 17:27:03 UTC, Jack Stouffer
wrote:
pragma(msg, is(int[] : long[]));
false
Why?
Think of the memory layout... if you implicitly casted, either
the contents would change or it would need to allocate a new
array, neither of which is free.
[0, 1] as int[] in memory is like [0,0,0,0,0,0,0,1].
[0, 1] as long[] in memory is like
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1].
It is twice as long! If you casted without the reallocation,
[0,1] as int[] becomes just plain [1] as long[] - the length
changes as well as the contents.
Sep 03 2015








"Adam D. Ruppe" <destructionator gmail.com>