digitalmars.D.bugs - [Issue 2542] New: array casts behave differently at compile and runtime
- d-bugmail puremagic.com (22/22) Dec 26 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2542
- d-bugmail puremagic.com (5/5) Dec 27 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2542
- d-bugmail puremagic.com (7/7) Dec 27 2008 http://d.puremagic.com/issues/show_bug.cgi?id=2542
- d-bugmail puremagic.com (11/11) Jan 06 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2542
- d-bugmail puremagic.com (9/9) Apr 03 2009 http://d.puremagic.com/issues/show_bug.cgi?id=2542
http://d.puremagic.com/issues/show_bug.cgi?id=2542 Summary: array casts behave differently at compile and runtime Product: D Version: 1.037 Platform: PC OS/Version: Linux Status: NEW Keywords: spec Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: kamm-removethis incasoftware.de This is related to casts of arrays not being documented: http://d.puremagic.com/issues/show_bug.cgi?id=2494 The issue is that the following produce different results: const short[] ct = cast(short[]) [cast(byte)1, 1]; // ct is [1, 1] short[] rt = cast(short[]) [cast(byte)1, 1].dup; // rt is [ 257 ] The runtime cast seems to be defined as 'reinterpret the data as an array of a different type, recompute the length' whereas the compile time cast seems to be 'convert each element to the other element type, keep length unchanged'. --
Dec 26 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2542 You're right, this is a documentation issue. Casts of array literals are treated differently. --
Dec 27 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2542 ------- While you're at it, could you also document these casts for string literals? short[] ct1 = cast(short[]) "\x01\x01"; // [ 257 ] short[] ct2 = cast(short[]) [cast(char)1, 1]; // [1, 1] even though both literals represent the same char[2] value. --
Dec 27 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2542 smjg iname.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |smjg iname.com So [cast(byte)1, 1] isn't a byte[], an int[] or anything like that, but of an internal 'array literal' type. Then why is [cast(byte)1, 1].dup not also of this internal 'array literal' type? --
Jan 06 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2542 clugdbug yahoo.com.au changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED Fixed DMD2.023 and DMD1.039 --
Apr 03 2009