Bug 2494 – describe explicit casting of arrays

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dlang.org
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2008-12-06T13:17:00Z
Last change time
2015-06-09T01:20:44Z
Keywords
spec
Assigned to
nobody
Creator
jlquinn
Depends on
3938

Comments

Comment #0 by jlquinn — 2008-12-06T13:17:13Z
It's possible and necessary at times to cast arrays for systems work. For example: ubyte[] ba = readdata(); uint[] = cast(uint[])ba; This isn't described and needs to be if it's supported in the language. I'm assuming it's supported, because otherwise many things would be difficult. Also, any limitations ala C++ aliasing rules need to be described.
Comment #1 by jarrett.billingsley — 2008-12-06T13:26:02Z
Huh, I would've expected it to be documented somewhere. But yes, it's legal, and will throw a runtime error if there is a size mismatch (that is, if the size of the array in bytes is not an even multiple of the destination type element size).
Comment #2 by hoganmeier — 2010-03-12T13:11:51Z
Comment #3 by github-bugzilla — 2012-01-22T20:14:07Z
Comment #4 by github-bugzilla — 2012-01-22T20:28:02Z