Per Inge Mathisen schreef: > On Mon, Mar 10, 2008 at 9:18 PM, Giel van Schijndel <[EMAIL PROTECTED]> wrote: >> > You will find that passing along a field belonging to >> > an object (psDroid->baseObject) and passing along an enlarged version >> > of an object ((BASE_OBJECT *)psDroid) are two very different things, >> > and to code to handle it has to be written differently. Eg BASE_OBJECT >> > *psTile->psObject cannot be cast back to DROID*, you need a pointer >> > back to the parent to do that, either by a void pointer or a union - >> > either way it gets ugly, IMHO. >> >> Actually in this example case you can just downcast baseObj to a DROID* >> without any problem (provided you checked the type properly), as both >> baseObj and droidObj start at the same address. > > Just to nitpick a little bit. You cannot downcast, since the memory > address points to the child object. Take this example:
Erm to use this example: typedef struct { some_type X; } a_new_type; a_new_type Y; Now my point is that the starting address of Y is _exactly_ the same to that of Y.X because Y.X is the first struct member of Y. -- Giel
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Warzone-dev mailing list Warzone-dev@gna.org https://mail.gna.org/listinfo/warzone-dev