struct to/from void, object to/from void

Jason King jhking at airmail.net
Sun Apr 29 17:28:14 PDT 2012


Thanks for the rapid reply.

>>    void* opCast() {
>>        return &this;
>>    }
>
>  Honestly, in my opinion, drop this. Don't make it more 
> 'pointer-like'. Unless there's a good reason, or it makes sense 
> (Mathematical), then don't. You keep having half the tests 
> using regular &(address) operator; what's wrong with that?
>
Since &thing works, I'm fine with it instead of opCast.  The
opCast was in the code I borrowed so I wanted to show both
approaches for someone to say "this way is better" (which you
did).

>
>  I'm not sure how safe casting an object to void* would be, or 
> back. If you can't avoid it, I would say make overloaded 
> methods that do the intermediate work and make it transparent 
> for you afterwards.

myobject.sizeof returns 4 (in 32 bit DMD) for every object I've
tested, so I'm inclined to suspect its a bog-standard pointer,
just what I'm looking to save and retrieve.
Anybody else want to chime in?





More information about the Digitalmars-d-learn mailing list