determining if a void* points to a valid Object
Luís Marques
luismarques+spam at gmail.com
Thu Aug 17 15:35:37 PDT 2006
nobody wrote:
> I think if I understand your question correctly then I believe what you
> can do if first assert( ptr !is null ). Now if I can define NotDObject
> and initialize the members I would do the following:
>
>
> struct NotDObject
> {
> int reserveredA = 0;
> int reserveredB = 0;
> // anything you want follows here
> }
>
> Now since we know ptr is not null then it it points to a NotDObject then
> dereferencing the pointer should give us a null value. Otherwise we now
> have a pointer to the vtable from the D ABI above.
>
> if((*(cast(void*)) is null ) // NotDObject
> else // Object
Yes, that's exactly what I need (thanks).
But 1) I guess reserveredB is unnecessary, no? 2) see my previous
question: 'can a D Object not have a vtable? That is, could the "pointer
to vtable" be null?' (what happens? it points to a 0 entry table?)
Luís
More information about the Digitalmars-d
mailing list