eina: provide a C++-compatible version of _EINA_INLIST_CONTAINER

In C++ we can't assign a void pointer to another type pointer without casts. We
now rely on typeof() operator *when using C++*.

We may provide another version later for those compilers without typeof()
support.



SVN revision: 63568
This commit is contained in:
Lucas De Marchi 2011-09-23 17:02:02 +00:00
parent 16fc152856
commit d091773382
1 changed files with 10 additions and 0 deletions

View File

@ -774,8 +774,18 @@ EAPI Eina_Inlist *eina_inlist_sort(Eina_Inlist *head, Eina_Compare_Cb func);
/* This two macros are helpers for the _FOREACH ones, don't use them */
#define _EINA_INLIST_OFFSET(ref) ((char *)&(ref)->__in_list - (char *)(ref))
#if !defined(__cplusplus)
#define _EINA_INLIST_CONTAINER(ref, ptr) (void *)((char *)(ptr) - \
_EINA_INLIST_OFFSET(ref))
#else
/*
* In C++ we can't assign a "type*" pointer to void* so we rely on GCC's typeof
* operator.
*/
#define _EINA_INLIST_CONTAINER(ref, ptr) (typeof(ref))((char *)(ptr) - \
_EINA_INLIST_OFFSET(ref))
#endif
#define EINA_INLIST_FOREACH(list, l) \
for (l = NULL, l = (list ? _EINA_INLIST_CONTAINER(l, list) : NULL); l; \