proposal: add bytesof Property, reduce pointer/cast requires
Janice Caron
caron800 at googlemail.com
Sat Nov 17 22:43:15 PST 2007
> byte[] bytesOf(T)(ref T t)
> {
> return (cast(byte*)&t)[0 .. t.sizeof];
> }
>
> byteArray[i .. i + struct.var.sizeof] = bytesOf(structVar);
> sendPacket(bytesOf(structVar));
That's the way to do it!
But since bytesOf() operates on an array, one could presumably also write
sendPacket(structVar.bytesOf);
which is what the orignal poster wanted. (Isn't D great?)
More information about the Digitalmars-d
mailing list