cast to void[]

Deewiant deewiant.doesnotlike.spam at gmail.com
Mon Feb 12 03:54:28 PST 2007


Alberto wrote:
> In general, if I have something like this:
> 
> struct pippo {
>    ushort a;
>    ushort b;
>    ubyte[170] c;
>    uint d;
> }
> 
> void do_something(void []);
> 
> What is the right way to pass pippo to do_something() ? something like #2 ?

I came up with the following. It seems idiomatic to me, but there might be
something smarter:

struct pippo {
   ushort a;
   ushort b;
   ubyte[170] c;
   uint d;
}

void do_something(void[] foo) {
	pippo* p = cast(pippo*)foo.ptr;
	assert (p.d == 2);
}

void main() {
	pippo p;
	p.d = 2;
	do_something((&p)[0..pippo.sizeof]);
}

-- 
Remove ".doesnotlike.spam" from the mail address.


More information about the Digitalmars-d-learn mailing list