www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2542] New: array casts behave differently at compile and runtime

reply d-bugmail puremagic.com writes:
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
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2542





------- Comment #1 from bugzilla digitalmars.com  2008-12-27 04:35 -------
You're right, this is a documentation issue. Casts of array literals are
treated differently.


-- 
Dec 27 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2542





------- Comment #2 from kamm-removethis incasoftware.de  2008-12-27 06:11
-------
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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2542


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com




------- Comment #3 from smjg iname.com  2009-01-06 06:53 -------
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
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2542


clugdbug yahoo.com.au changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #4 from clugdbug yahoo.com.au  2009-04-03 07:42 -------
Fixed DMD2.023 and DMD1.039


-- 
Apr 03 2009