determining if a void* points to a valid Object
Sean Kelly
sean at f4.ca
Thu Aug 17 14:39:18 PDT 2006
Luís Marques wrote:
> Hello all,
>
> I'm making a transition of a code base from C to D. I wish to alleviate
> the transition by making it gradual, but that requires being able to
> distinguish D Objects from the existing C structs, given a pointer.
>
> Could you help me with this please?
>
> 1. You have a "void *ptr".
> 2. You have a struct NotDObject whose declaration you can control. (e.g.
> add fields and require that they possess certain values)
>
> How do you determine with fairly good reliability if ptr points to an
> Object or to a NotDObject struct?
It would be a horrible hack, but you might be able to test whether the
location reserved for the vtbl ptr points to a location where vtbls are
known to reside. The ABI might be of help here:
http://www.digitalmars.com/d/abi.html You will have to ask Walter or do
some sleuthing to sort out how to determine this address range, however.
Sean
More information about the Digitalmars-d
mailing list