DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] headers: typeof -> __typeof__ to unbreak C++11 code
@ 2015-02-25 13:28 Simon Kagstrom
  2015-02-26 11:14 ` Thomas Monjalon
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Simon Kagstrom @ 2015-02-25 13:28 UTC (permalink / raw)
  To: dev

When compiling C++11-code or above (--std=c++11), the build fails with
lots of

  rte_eth_ctrl.h:517:3: note: in expansion of macro RTE_ALIGN
    (RTE_ALIGN(RTE_ETH_FLOW_MAX, UINT32_BIT)/UINT32_BIT)
    ^

When reading the GCC info pages, I get the feeling that __typeof__ is
a better choice, and that indeed works when including the headers in
C++ files (--std=c++11).

There are some typeof()s left in C files, the patch only touches the
public API.

Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
---
 lib/librte_acl/acl_vect.h                  |  8 ++++----
 lib/librte_eal/common/include/rte_common.h | 17 +++++++++--------
 lib/librte_eal/common/include/rte_pci.h    |  2 +-
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/lib/librte_acl/acl_vect.h b/lib/librte_acl/acl_vect.h
index 6cc1999..de47071 100644
--- a/lib/librte_acl/acl_vect.h
+++ b/lib/librte_acl/acl_vect.h
@@ -52,8 +52,8 @@ extern "C" {
  * hi - contains high 32 bits of given N transitions.
  */
 #define	ACL_TR_HILO(P, TC, tr0, tr1, lo, hi)                        do { \
-	lo = (typeof(lo))_##P##_shuffle_ps((TC)(tr0), (TC)(tr1), 0x88);  \
-	hi = (typeof(hi))_##P##_shuffle_ps((TC)(tr0), (TC)(tr1), 0xdd);  \
+	lo = (__typeof__(lo))_##P##_shuffle_ps((TC)(tr0), (TC)(tr1), 0x88);  \
+	hi = (__typeof__(hi))_##P##_shuffle_ps((TC)(tr0), (TC)(tr1), 0xdd);  \
 } while (0)
 
 
@@ -74,8 +74,8 @@ extern "C" {
 	addr, index_mask, next_input, shuffle_input,		\
 	ones_16, range_base, tr_lo, tr_hi)               do {	\
 								\
-	typeof(addr) in, node_type, r, t;			\
-	typeof(addr) dfa_msk, dfa_ofs, quad_ofs;		\
+	__typeof__(addr) in, node_type, r, t;			\
+	__typeof__(addr) dfa_msk, dfa_ofs, quad_ofs;		\
 								\
 	t = _##P##_xor_si##S(index_mask, index_mask);		\
 	in = _##P##_shuffle_epi8(next_input, shuffle_input);	\
diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h
index 8ac940c..40c2603 100644
--- a/lib/librte_eal/common/include/rte_common.h
+++ b/lib/librte_eal/common/include/rte_common.h
@@ -43,6 +43,7 @@
 
 #ifdef __cplusplus
 extern "C" {
+
 #endif
 
 #include <stdint.h>
@@ -112,7 +113,7 @@ rte_align_floor_int(uintptr_t ptr, uintptr_t align)
  * must be a power-of-two value.
  */
 #define RTE_PTR_ALIGN_FLOOR(ptr, align) \
-	(typeof(ptr))rte_align_floor_int((uintptr_t)ptr, align)
+	(__typeof__(ptr))rte_align_floor_int((uintptr_t)ptr, align)
 
 /**
  * Macro to align a value to a given power-of-two. The resultant value
@@ -121,7 +122,7 @@ rte_align_floor_int(uintptr_t ptr, uintptr_t align)
  * power-of-two value.
  */
 #define RTE_ALIGN_FLOOR(val, align) \
-	(typeof(val))((val) & (~((typeof(val))((align) - 1))))
+	(__typeof__(val))((val) & (~((__typeof__(val))((align) - 1))))
 
 /**
  * Macro to align a pointer to a given power-of-two. The resultant
@@ -130,7 +131,7 @@ rte_align_floor_int(uintptr_t ptr, uintptr_t align)
  * must be a power-of-two value.
  */
 #define RTE_PTR_ALIGN_CEIL(ptr, align) \
-	RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
+	RTE_PTR_ALIGN_FLOOR((__typeof__(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
 
 /**
  * Macro to align a value to a given power-of-two. The resultant value
@@ -139,7 +140,7 @@ rte_align_floor_int(uintptr_t ptr, uintptr_t align)
  * value.
  */
 #define RTE_ALIGN_CEIL(val, align) \
-	RTE_ALIGN_FLOOR(((val) + ((typeof(val)) (align) - 1)), align)
+	RTE_ALIGN_FLOOR(((val) + ((__typeof__(val)) (align) - 1)), align)
 
 /**
  * Macro to align a pointer to a given power-of-two. The resultant
@@ -257,8 +258,8 @@ rte_align64pow2(uint64_t v)
  * Macro to return the minimum of two numbers
  */
 #define RTE_MIN(a, b) ({ \
-		typeof (a) _a = (a); \
-		typeof (b) _b = (b); \
+		__typeof__ (a) _a = (a); \
+		__typeof__ (b) _b = (b); \
 		_a < _b ? _a : _b; \
 	})
 
@@ -266,8 +267,8 @@ rte_align64pow2(uint64_t v)
  * Macro to return the maximum of two numbers
  */
 #define RTE_MAX(a, b) ({ \
-		typeof (a) _a = (a); \
-		typeof (b) _b = (b); \
+		__typeof__ (a) _a = (a); \
+		__typeof__ (b) _b = (b); \
 		_a > _b ? _a : _b; \
 	})
 
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 3df07e8..bc065d4 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -212,7 +212,7 @@ do {                                                               \
 	val = strtoul((in), &end, 16);                          \
 	if (errno != 0 || end[0] != (dlm) || val > (lim))       \
 		return (-EINVAL);                               \
-	(fd) = (typeof (fd))val;                                \
+	(fd) = (__typeof__ (fd))val;                            \
 	(in) = end + 1;                                         \
 } while(0)
 
-- 
1.9.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2015-03-09 16:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-25 13:28 [dpdk-dev] [PATCH] headers: typeof -> __typeof__ to unbreak C++11 code Simon Kagstrom
2015-02-26 11:14 ` Thomas Monjalon
2015-02-26 11:24   ` Simon Kågström
2015-02-26 16:02   ` Mcnamara, John
2015-02-27 16:24 ` Ananyev, Konstantin
2015-03-02  7:55   ` Simon Kågström
2015-03-06  8:28     ` Simon Kågström
2015-03-06 10:30       ` Ananyev, Konstantin
2015-03-06 13:42         ` Simon Kågström
2015-03-06 15:59 ` [dpdk-dev] [PATCHv2] " Konstantin Ananyev
2015-03-09 16:38   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).