Bug 19683 – casting int[] array literal or enum to ubyte[] does element-wise cast
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2019-02-17T20:54:11Z
Last change time
2019-02-17T21:33:00Z
Assigned to
No Owner
Creator
Dennis
Comments
Comment #0 by dkorpel — 2019-02-17T20:54:11Z
When an array literal of type int[] is casted to a ubyte[] the result has the same length and all integers are truncated to ubytes, while normally it would result in an array 4 times the length of the int[] with the same underlying data.
See: https://forum.dlang.org/post/[email protected]
```
void main ()
{
enum A = [0x10203040, 0x50607080];
auto B = [0x10203040, 0x50607080];
assert (A == B);
auto p = cast (ubyte []) A;
auto q = cast (ubyte []) B;
assert (p == q); // fails
}
```
Relevant spec: https://dlang.org/spec/expression.html#cast_expressions
Comment #1 by dlang-bugzilla — 2019-02-17T21:33:00Z
*** This issue has been marked as a duplicate of issue 16357 ***