On Thu, 30 Apr 2009 18:02:45 -0300 Gustavo Sverzut Barbieri
<barbi...@profusion.mobi> said:

> On Thu, Apr 30, 2009 at 10:11 AM, Albin Tonnerre
> <albin.tonne...@gmail.com> wrote:
> > Hello,
> >
> > While playing with Eina_Inlist, I noticed that given a pointer to an
> > Eina_Inlist, one can't easily get a pointer to the structure containing it.
> > The only option now is to put the Eina_Inlist first in the structure, and
> > then cast this structure to an Eina_Inlist, which is far from optimal.
> > I'd therefore like to propose that we add in eina_inlist.h a macro along the
> > lines of
> >
> > #define FIND_A_SENSBILE_NAME_FOR_THIS(ptr, type) ((type *) ((Eina_Inlist *)
> > #ptr - offsetof(type, __in_list)))
> >
> > Then, we could get a pointer to the containing structure, no matter where
> > the Eina_Inlist is (note that I used __in_list as the member as we already
> > have a macro '#define EINA_INLIST Eina_Inlist __in_list', but a member
> > argument could be added just as well)
> >
> > Thoughts ?
> 
> As we discussed on IRC, I like this. It would help avoid casts and try
> to make code bit easier to get right.

much uglier as now you need to drag an offset # around all the time, and now
you still need to cast anyway (use a raw pointer offset and cast to ah Inlist
pointer). you don't get rid of it.

inheritance in c in the end requires casting. thats how c does it. dont be
afraid of casting or think its ugly. it's how c becomes powerful and flexible.

-- 
------------- Codito, ergo sum - "I code, therefore I am" --------------
The Rasterman (Carsten Haitzler)    ras...@rasterman.com


------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations 
Conference from O'Reilly Media. Velocity features a full day of 
expert-led, hands-on workshops and two days of sessions from industry 
leaders in dedicated Performance & Operations tracks. Use code vel09scf 
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to