From e36396171d05d3c1528f87844db7b944dc72b970 Mon Sep 17 00:00:00 2001 From: lucas Date: Fri, 23 Sep 2011 17:02:02 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@63568 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/include/eina_inlist.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/include/eina_inlist.h b/src/include/eina_inlist.h index 75207dc..1b3ab27 100644 --- a/src/include/eina_inlist.h +++ b/src/include/eina_inlist.h @@ -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; \ -- 2.7.4