Skip to contentSkip to conversation

node: fix C++ compatibility errors (option 2)

PATCH Applied Bruce Richardson 3 participants 4 messages Jun 30, 2025 – Jul 2, 2025

lore
Share & tools
lore
#0 lore raw

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.

Fixes 746e8736da70 ("node: add global mbuf dynfield")
---
 lib/node/rte_node_mbuf_dynfield.h | 2 ++
 1 file changed, 2 insertions(+)
lib/node/rte_node_mbuf_dynfield.h +2 -0
index b77fdbb94f..09254c585a 100644
@@ -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
#1 lore raw

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_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.

[...]

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.

Acked-by on v1 1/1
#2 lore raw
In reply to Bruce Richardson
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_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.

Fixes 746e8736da70 ("node: add global mbuf dynfield")
---
 lib/node/rte_node_mbuf_dynfield.h | 2 ++
 1 file changed, 2 insertions(+)
lib/node/rte_node_mbuf_dynfield.h +2 -1
index b77fdbb94f..09254c585a 100644
@@ -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

#3 lore raw

01/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_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.

Quoted 5 lines
Quoted 3 lines
Fixes 746e8736da70 ("node: add global mbuf dynfield")

Applied, thanks.