cast to void[]
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Mon Feb 12 09:58:32 PST 2007
Alberto wrote:
> I have some problem casting a struct to void[]:
>
[snip]
> // #3
> Signature sig3 =
> rsatest.sign(cast(void[])((&buf)[0..RSAEncryptedData.sizeof]), Hash.SHA512);
> ret =
> rsatest.verifySig(cast(void[])((&buf)[0..RSAEncryptedData.sizeof]),
> sig3, Hash.SHA512);
> assert(ret == true);
That RSAEncryptedData.sizeof should be 1, since you're slicing a value
of type RSAEncryptedData*.
>
> return 0;
> }
>
> I got an Assertion failure on the 3° assert, where I have tried to cast
> buf directly to void[].
> 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 ?
My preferred way is something like
---
pippo somevar;
// ... initialize
do_something((&somevar)[0..1]);
---
(The inner brackets may be superfluous, but I'm not sure. My rule of
thumb in such cases is to always put them in there, because even if the
code does exactly the same they make it more clear what's happening)
More information about the Digitalmars-d-learn
mailing list