node: fix C++ compatibility errors (option 2)
PATCH 1/1 node: fix C++ compatibility errors (option 2)
C++ does not allow zero-sized unions - they end up being of size 1-byte, which leads to C/C++ compatibility issues, flagged by the compiler.
lib/node/rte_node_mbuf_dynfield.h:78:2: error: union has size 0 in C,
size 1 in C++ [-Werror,-Wextern-c-compat]
78 | union {
| ^
1 error generated.
Fix the error by omitting the persistent_data field when it is zero-sized, since it's unusable. Any app using the field must already specify a size for the persistent data.
--- lib/node/rte_node_mbuf_dynfield.h | 2 ++ 1 file changed, 2 insertions(+)
lib/node/rte_node_mbuf_dynfield.h +2 -0
@@ -69,6 +69,7 @@ typedef struct rte_node_mbuf_overload_fields {* 2. Overloadable fields: Fields which can be repurposed by two adjacent nodes. */ typedef struct rte_node_mbuf_dynfield { +#if RTE_NODE_MBUF_PERSISTENT_FIELDS_SIZE > 0 /** * Persistent mbuf region across nodes in graph walk *
@@ -78,6 +79,7 @@ typedef struct rte_node_mbuf_dynfield {union {uint8_t persistent_data[RTE_NODE_MBUF_PERSISTENT_FIELDS_SIZE ]; }; +#endif /** * Overloadable mbuf fields across graph walk. Fields which can change. *
Signature · 1 line
2.48.1
30/06/2025 12:50, Bruce Richardson:
Quoted 12 lines
C++ does not allow zero-sized unions - they end up being of size 1-byte, which leads to C/C++ compatibility issues, flagged by the compiler.
lib/node/rte_node_mbuf_dynfield.h:78:2: error: union has size 0 in C,
size 1 in C++ [-Werror,-Wextern-c-compat]
78 | union {
| ^
1 error generated.Fix the error by omitting the
persistent_datafield when it is zero-sized, since it's unusable. Any app using the field must already specify a size for the persistent data.
[...]
Quoted 11 lines
lib/node/rte_node_mbuf_dynfield.h +1
-0@@ -69,6 +69,7 @@ typedef struct rte_node_mbuf_overload_fields {* 2. Overloadable fields: Fields which can be repurposed by two adjacent nodes. */ typedef struct rte_node_mbuf_dynfield { +#if RTE_NODE_MBUF_PERSISTENT_FIELDS_SIZE > 0 /** * Persistent mbuf region across nodes in graph walk *
lib/node/rte_node_mbuf_dynfield.h typedef struct rte_node_mbuf_dynfield { · line 82
Quoted 4 lines
lib/node/rte_node_mbuf_dynfield.h +1
-0@@ -78,6 +79,7 @@ typedef struct rte_node_mbuf_dynfield {union {uint8_t persistent_data[RTE_NODE_MBUF_PERSISTENT_FIELDS_SIZE ]; }; +#endif
I didn't do a deep analysis but I think I would prefer this option 2.
Quoted 42 lines · Bruce Richardson
C++ does not allow zero-sized unions - they end up being of size 1-byte, which leads to C/C++ compatibility issues, flagged by the compiler.
lib/node/rte_node_mbuf_dynfield.h:78:2: error: union has size 0 in C,
size 1 in C++ [-Werror,-Wextern-c-compat]
78 | union {
| ^
1 error generated.Fix the error by omitting the
persistent_datafield when it is zero-sized, since it's unusable. Any app using the field must already specify a size for the persistent data.Fixes 746e8736da70 ("node: add global mbuf dynfield")Signed-off-by Bruce Richardson <[email protected]>--- lib/node/rte_node_mbuf_dynfield.h | 2 ++ 1 file changed, 2 insertions(+)lib/node/rte_node_mbuf_dynfield.h +2
-1@@ -69,6 +69,7 @@ typedef struct rte_node_mbuf_overload_fields {* 2. Overloadable fields: Fields which can be repurposed by two adjacent nodes. */ typedef struct rte_node_mbuf_dynfield { +#if RTE_NODE_MBUF_PERSISTENT_FIELDS_SIZE > 0 /** * Persistent mbuf region across nodes in graph walk *@@ -78,6 +79,7 @@ typedef struct rte_node_mbuf_dynfield {union {uint8_t persistent_data[RTE_NODE_MBUF_PERSISTENT_FIELDS_SIZE ]; }; +#endif /** * Overloadable mbuf fields across graph walk. Fields which can change. * --
Quoted 2 lines
2.48.1
Thomas Monjalon
Applied01/07/2025 16:48, Nitin Saxena:
Quoted 16 lines
Quoted 14 lines · Bruce Richardson
C++ does not allow zero-sized unions - they end up being of size 1-byte, which leads to C/C++ compatibility issues, flagged by the compiler.
lib/node/rte_node_mbuf_dynfield.h:78:2: error: union has size 0 in C,
size 1 in C++ [-Werror,-Wextern-c-compat]
78 | union {
| ^
1 error generated.Fix the error by omitting the
persistent_datafield when it is zero-sized, since it's unusable. Any app using the field must already specify a size for the persistent data.
Quoted 5 lines
Quoted 3 lines
Fixes 746e8736da70 ("node: add global mbuf dynfield")Signed-off-by Bruce Richardson <[email protected]>Acked-by Nitin Saxena <[email protected]>
Applied, thanks.