headers: typeof -> __typeof__ to unbreak C++11 code
PATCH 1/1 headers: typeof -> __typeof__ to unbreak C++11 code
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.
--- 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(-)
lib/librte_acl/acl_vect.h +4 -4
@@ -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); \
lib/librte_eal/common/include/rte_common.h +9 -8
@@ -43,6 +43,7 @@#ifdef __cplusplusextern "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; \ })
lib/librte_eal/common/include/rte_pci.h +1 -1
@@ -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 )
Signature · 1 line
1.9.1
Hi Simon,
2015-02-25 14:28, Simon Kagstrom:
Quoted 10 lines
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).
I'd like to be sure that it's working with every compilers we support (gcc, icc, clang).
Anyone to check please?
Quoted 10 lines · Thomas Monjalon
2015-02-25 14:28, Simon Kagstrom:
Quoted 6 lines
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) ^I'd like to be sure that it's working with every compilers we support (gcc, icc, clang).
Anyone to check please?
I guess you mean compiling DPDK itself, but I can add that compiling my example "app" (i.e., a file which includes the DPDK headers and an empty main()) with clang++ gives more problems:
include/rte_devargs.h:89:5: error:
'virtual' can only appear on non-static member functions
} virtual;
^and a slew of warnings of the type
include/rte_byteorder_64.h:45:2: warning:
'register' storage class specifier is deprecated
[-Wdeprecated-register]
register uint64_t x = _x;
^~~~~~~~~include/rte_memcpy.h:85:25: warning:
cast from 'const uint8_t *' (aka 'const unsigned char *') to 'const __m128i *' increases required alignment from 1 to 16
[-Wcast-align]
xmm0 = _mm_loadu_si128((const __m128i *)src);
// Simon
Quoted 11 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Thomas Monjalon
Sent: Thursday, February 26, 2015 11:15 AM
To: [email protected]; Simon Kagstrom
Subject: Re: [dpdk-dev] [PATCH] headers: typeof ->__typeof__to unbreak C++11 codeI'd like to be sure that it's working with every compilers we support (gcc, icc, clang).
Anyone to check please?
Hi,
The patch works with:
gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)
icc (ICC) 13.1.1 20130313
clang version 3.3 (tags/RELEASE_33/rc2)Regards,
John
Quoted 130 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Simon Kagstrom
Sent: Wednesday, February 25, 2015 1:29 PM
To: [email protected]
Subject: [dpdk-dev] [PATCH] headers: typeof ->__typeof__to unbreak C++11 codeWhen 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.
--- 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(-)lib/librte_acl/acl_vect.h +4
-4@@ -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); \lib/librte_eal/common/include/rte_common.h +9
-8@@ -43,6 +43,7 @@#ifdef __cplusplusextern "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; \ })lib/librte_eal/common/include/rte_pci.h +0
-0
lib/librte_eal/common/include/rte_pci.h do { \
Quoted 9 lines
lib/librte_eal/common/include/rte_pci.h +1
-2@@ -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 ) --
Actually, I wonder wouldn't something like the one below be sufficient? Konstantin
lib/librte_eal/common/include/rte_common.h +9 -0
@@ -51,6 +51,15 @@ extern "C" {#include <errno.h> #include <limits.h> +#ifndef typeof +#define typeof __typeof__ +#endif + +#ifndef asm +#define asm __asm__ +#endif + +/*********** Macros to eliminate unused variable warnings ********/ /**
A message that is not in the archive (sent off-list or not yet received): 2601191342CEEE43887BDE71AB977258213F3012-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org
Quoted 7 lines · Konstantin
Actually, I wonder wouldn't something like the one below be sufficient?
lib/librte_eal/common/include/rte_common.h +0
-0
lib/librte_eal/common/include/rte_common.h extern "C" { · line 60
Quoted 10 lines
lib/librte_eal/common/include/rte_common.h +7
-0@@ -51,6 +51,15 @@ extern "C" {#include <errno.h> #include <limits.h> +#ifndef typeof +#define typeof __typeof__ +#endif + +#ifndef asm +#define asm __asm__ +#endif
Yes, I've tested, and this works with g++ as well.
// Simon
A message that is not in the archive (sent off-list or not yet received): 54F41765.1050403-vI6UBbBVNY+JA8cjQkG2/[email protected]
Ping? Konstantins simpler patch is fine for me, but at least one of these two would be very nice to have so that modern C++ code can use DPDK.
// Simon
Quoted 23 lines · Simon Kågström
Quoted 7 lines · Konstantin
Actually, I wonder wouldn't something like the one below be sufficient?
lib/librte_eal/common/include/rte_common.h +0
-0lib/librte_eal/common/include/rte_common.h extern "C" { · line 60
Quoted 10 lines
lib/librte_eal/common/include/rte_common.h +7
-0@@ -51,6 +51,15 @@ extern "C" {#include <errno.h> #include <limits.h> +#ifndef typeof +#define typeof __typeof__ +#endif + +#ifndef asm +#define asm __asm__ +#endif Yes, I've tested, and this works with g++ as well.
// Simon
A message that is not in the archive (sent off-list or not yet received): 54F9651B.7060603-vI6UBbBVNY+JA8cjQkG2/[email protected]
Hi Simon,
Quoted 10 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Simon Kågström
Sent: Friday, March 06, 2015 8:28 AM
To: [email protected]
Subject: Re: [dpdk-dev] [PATCH] headers: typeof ->__typeof__to unbreak C++11 codePing? Konstantins simpler patch is fine for me, but at least one of these two would be very nice to have so that modern C++ code can use DPDK.
// Simon
Can you do v2 as suggested, or do you want me to do it? Thanks
Konstantin
Quoted 25 lines · Simon Kågström
Quoted 23 lines · Konstantin
Quoted 7 lines
Actually, I wonder wouldn't something like the one below be sufficient?
lib/librte_eal/common/include/rte_common.h +0
-0lib/librte_eal/common/include/rte_common.h extern "C" { · line 60
Quoted 10 lines
lib/librte_eal/common/include/rte_common.h +7
-0@@ -51,6 +51,15 @@ extern "C" {#include <errno.h> #include <limits.h> +#ifndef typeof +#define typeof __typeof__ +#endif + +#ifndef asm +#define asm __asm__ +#endif Yes, I've tested, and this works with g++ as well.
// Simon
A message that is not in the archive (sent off-list or not yet received): 2601191342CEEE43887BDE71AB977258213F44D4-pww93C2UFcwu0RiL9chJVbfspsVTdybXVpNB7YpNyf8@public.gmane.org
Quoted 9 lines · Konstantin
Hi Simon,
Quoted 6 lines
-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Simon Kågström
Sent: Friday, March 06, 2015 8:28 AM
To: [email protected]
Subject: Re: [dpdk-dev] [PATCH] headers: typeof ->__typeof__to unbreak C++11 code
Quoted 4 lines
Quoted 3 lines
Ping? Konstantins simpler patch is fine for me, but at least one of these two would be very nice to have so that modern C++ code can use DPDK.
Can you do v2 as suggested, or do you want me to do it?
You wrote that patch (which looks better than mine), so feel free to submit it!
Thanks,
// Simon
PATCH v2 1/1 headers: typeof -> __typeof__ to unbreak C++11 code
In reply to Simon Kagstromv2:
Instead of changing all the affected files,
define 'typeofi' and 'asm' if needed.
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.
--- lib/librte_eal/common/include/rte_common.h | 9 +++++++++ 1 file changed, 9 insertions(+)
lib/librte_eal/common/include/rte_common.h +9 -0
@@ -51,6 +51,15 @@ extern "C" {#include <errno.h> #include <limits.h> +#ifndef typeof +#define typeof __typeof__ +#endif + +#ifndef asm +#define asm __asm__ +#endif + +/*********** Macros to eliminate unused variable warnings ********/ /**
Signature · 1 line
1.8.5.3
A message that is not in the archive (sent off-list or not yet received): 1425657587-23516-1-git-send-email-konstantin.ananyev-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Thomas Monjalon
Applied2015-03-06 15:59, Konstantin Ananyev:
Quoted 15 lines
v2:
Instead of changing all the affected files,
define 'typeofi' and 'asm' if needed.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).
Quoted 5 lines
There are some typeof()s left in C files, the patch only touches the public API.
Signed-off-by Konstantin Ananyev <[email protected]>
Applied, thanks