data mapping, more elegant solution?
Regan Heath
regan at netmail.co.nz
Thu Dec 13 05:35:35 PST 2007
mandel wrote:
> Hi,
>
> I want to map a uint to a position of an ubyte array.
> Atm. I use this:
>
> ubyte[8] array;
> *cast(uint*) &array.ptr[0] = 42;
>
> But is there a nicer solution to do achive this?
>
> Smth. like "array[0..4] = 42;", but this tries to assign 42 to every
> byte (resulting in [0x2a, 0x2a, 0x2a, 0x2a, 0x00, 0x00, 0x00, 0x00]).
Use a union?
union thing
{
ubyte[8] ub;
uint ui;
}
void main()
{
thing a;
a.ui = 42;
}
Regan
More information about the Digitalmars-d-learn
mailing list