[Issue 8901] a bug to cast from array literal to ubyte[]
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Oct 27 13:21:38 PDT 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8901
hsteoh at quickfur.ath.cx changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |hsteoh at quickfur.ath.cx
--- Comment #1 from hsteoh at quickfur.ath.cx 2012-10-27 13:21:36 PDT ---
I don't understand, why should this work?
D arrays are not the same as C arrays; casting an int into an array does not
magically make it an array of bytes.
If you want to get the byte representation, you need to do something like this:
int a = 1234;
ubyte* ptr = cast(ubyte*)&a;
writeln(ptr[0 .. int.sizeof]);
Note, though, that this is unsafe, and is generally not recommended in D code,
unless you're writing low-level code.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list