eina: provide a C++-compatible version of _EINA_INLIST_CONTAINER
authorlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 23 Sep 2011 17:02:02 +0000 (17:02 +0000)
committerlucas <lucas@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 23 Sep 2011 17:02:02 +0000 (17:02 +0000)
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

index 75207dc..1b3ab27 100644 (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; \