On Fri, May 01, 2009 at 10:13:09AM +1000, Carsten Haitzler wrote : > 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 Well, if the Eina_Inlist is the first member in the struct the compiler will probably optimize the substraction, as the offset would be 0. If it's not the first member, you need it anyway. > # 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. Same here. The point is not only to avoid casts. It allows people to place the inlist wherever they want within a structure, and have easy access to it. Providing it in eina just doesn't cost anything, and allows people to do it painlessly. -- Albin Tonnerre
signature.asc
Description: Digital signature
------------------------------------------------------------------------------ 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