http://d.puremagic.com/issues/show_bug.cgi?id=7328

           Summary: Allow casting between ubyte[4] and int
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: jmdavisp...@gmx.com


--- Comment #0 from Jonathan M Davis <jmdavisp...@gmx.com> 2012-01-20 11:10:23 
PST ---
It would be very nice to be able to cast between arrays of ubyte and integral
type as long as they're the same size. So, ubyte[4] -> int, ubyte[2] -> short,
etc. Maybe even ubyteArr[0 .. 4] -> int as long as the indices are known at
compile time.

As it stands, the only two ways that I can think of doing this are to use a
union, e.g.

union IntegerT)
    if(isIntegral!T)
{
    Unqual!T value;
    ubyte[T.sizeof] array;
}

or to do some nasty casting, e.g.

ubyte[4] a = (cast(ubyte*)[0x28A].ptr)[0 .. 4];
int b = (cast(int*)a.ptr)[0];

It would be much easier to manipulate buffers (which are generally arrays of
ubytes) if casting between static arrays (and preferrably even dynamic arrays
if the indices are known at compile time) and integral values - as long as the
lengths match of course.

Worst case, something can be added to std.bitmanip to do this, but I'm a bit
surprised that that casts such as cast(ubyte[4])7 aren't allowed by the
compiler.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to