Skip to contentSkip to conversation

doc: drop recommendation against bool in structures

PATCH Applied Maxime Leroy 5 participants 7 messages Jul 20 – Jul 22

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 doc: drop recommendation against bool in structures

The coding style advised against bool in structures, citing space and type-size concerns inherited from the Linux kernel. That does not match DPDK practice: bool is already used in over 1400 structure fields across the tree, including core APIs such as rte_flow. Drop the note so the style guide reflects actual usage.

---
 doc/guides/contributing/coding_style.rst | 9 ---------
 1 file changed, 9 deletions(-)
doc/guides/contributing/coding_style.rst +0 -9
index 976a1e1de3..11de3bb39a 100644
@@ -313,15 +313,6 @@ Structure Declarations
 * Use of the structures should be by separate variable declarations and those declarations must be extern if they are declared in a header file.
 * Externally visible structure definitions should have the structure name prefixed by ``rte_`` to avoid namespace collisions.
 
-.. note::
-
-    Avoid using ``bool`` in structures because it wastes space and
-    the type size is unclear. A preferred use of
-    ``bool`` is mainly as a return type from functions that return true/false,
-    and maybe local variable functions.
-
-    Ref: `LKML <https://lkml.org/lkml/2017/11/21/384>`_
-
 Queues
 ~~~~~~
 
Signature · 1 line
2.43.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Maxime Leroy

The coding style advised against bool in structures, citing space and type-size concerns inherited from the Linux kernel. That does not match DPDK practice: bool is already used in over 1400 structure fields across the tree, including core APIs such as rte_flow. Drop the note so the style guide reflects actual usage.

---

Definite +1

Quoted 26 lines
 doc/guides/contributing/coding_style.rst | 9 ---------
 1 file changed, 9 deletions(-)
doc/guides/contributing/coding_style.rst +0 -9
index 976a1e1de3..11de3bb39a 100644
@@ -313,15 +313,6 @@ Structure Declarations
 * Use of the structures should be by separate variable declarations and those declarations must be extern if they are declared in a header file.
 * Externally visible structure definitions should have the structure name prefixed by ``rte_`` to avoid namespace collisions.
 
-.. note::
-
-    Avoid using ``bool`` in structures because it wastes space and
-    the type size is unclear. A preferred use of
-    ``bool`` is mainly as a return type from functions that return true/false,
-    and maybe local variable functions.
-
-    Ref: `LKML <https://lkml.org/lkml/2017/11/21/384>`_
-
 Queues
 ~~~~~~
 
Signature · 1 line
2.43.0
#2 lore raw
Quoted 11 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 20 July 2026 14.13

Quoted 2 lines · Maxime Leroy

The coding style advised against bool in structures, citing space and type-size concerns inherited from the Linux kernel. That does not

match

Quoted 1 line

DPDK practice: bool is already used in over 1400 structure fields

across

Quoted 2 lines

the tree, including core APIs such as rte_flow. Drop the note so the style guide reflects actual usage.

The note is still valid, although massively violated.
Could we paraphrase the note as an advice/recommendation, instead of completely removing it? The intention is to make developers consider alternatives when adding a Boolean field to a structure. Maybe it could be expanded with a few example alternatives:
uint8_t value, or
uintN_t value:1 (bitfield).

Quoted 39 lines
Quoted 3 lines

---

Definite +1

Review

Quoted 4 lines
 doc/guides/contributing/coding_style.rst | 9 ---------
 1 file changed, 9 deletions(-)
(quoted diff) +0 -0

b/doc/guides/contributing/coding_style.rst

doc/guides/contributing/coding_style.rst Structure Declarations · line 313

Quoted 5 lines

index 976a1e1de3..11de3bb39a 100644

doc/guides/contributing/coding_style.rst +0 -0
@@ -313,15 +313,6 @@ Structure Declarations
 * Use of the structures should be by separate variable declarations

and those declarations must be extern if they are declared in a header file.

doc/guides/contributing/coding_style.rst Structure Declarations · line 314

Quoted 1 line
doc/guides/contributing/coding_style.rst +0 -0
 * Externally visible structure definitions should have the structure

name prefixed by ``rte_`` to avoid namespace collisions.

doc/guides/contributing/coding_style.rst Structure Declarations

Quoted 6 lines
doc/guides/contributing/coding_style.rst +0 -5
-.. note::
-
-    Avoid using ``bool`` in structures because it wastes space and
-    the type size is unclear. A preferred use of
-    ``bool`` is mainly as a return type from functions that return

true/false,

Quoted 10 lines
doc/guides/contributing/coding_style.rst +0 -5
-    and maybe local variable functions.
-
-    Ref: `LKML <https://lkml.org/lkml/2017/11/21/384>`_
-
 Queues
 ~~~~~~
 
--

2.43.0

#3 lore raw
Quoted 12 lines · Morten Brørup
Quoted 11 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 20 July 2026 14.13

Quoted 2 lines · Maxime Leroy

The coding style advised against bool in structures, citing space and type-size concerns inherited from the Linux kernel. That does not

match

Quoted 1 line

DPDK practice: bool is already used in over 1400 structure fields

across

Quoted 2 lines

the tree, including core APIs such as rte_flow. Drop the note so the style guide reflects actual usage.

Quoted 7 lines

The note is still valid, although massively violated.
Could we paraphrase the note as an advice/recommendation, instead of completely removing it? The intention is to make developers consider alternatives when adding a Boolean field to a structure. Maybe it could be expanded with a few example alternatives:
uint8_t value, or
uintN_t value:1 (bitfield).

I don't think we want those alternative approaches. If something is a boolean value, then let's just store it as a bool and be done with it. If we store it as an int type then we need comments documenting that it's actually a flag. If it's a bit type, then the field becomes just that little bit more awkward to manage - though still a good choice if the struct is size-sensitive.

Because of this, I'd be in favour of just removing the text and then letting the developer choose the best field type for the job. If bool is a bad choice for a given situation, that should be caught in review.

/Bruce

#4 lore raw
Quoted 35 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 20 July 2026 14.58

Quoted 5 lines · Morten Brørup
Quoted 5 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 20 July 2026 14.13

Quoted 1 line · Maxime Leroy

The coding style advised against bool in structures, citing space

and

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

type-size concerns inherited from the Linux kernel. That does not

match

Quoted 1 line

DPDK practice: bool is already used in over 1400 structure fields

across

Quoted 1 line

the tree, including core APIs such as rte_flow. Drop the note so

the

Quoted 4 lines
Quoted 1 line
Quoted 1 line

style guide reflects actual usage.

The note is still valid, although massively violated. Could we paraphrase the note as an advice/recommendation, instead of

completely removing it?

Quoted 1 line

The intention is to make developers consider alternatives when adding

a Boolean field to a structure.

Quoted 4 lines

Maybe it could be expanded with a few example alternatives:
uint8_t value, or
uintN_t value:1 (bitfield).

I don't think we want those alternative approaches. If something is a boolean value, then let's just store it as a bool and be done with it. If
we store it as an int type then we need comments documenting that it's actually a flag. If it's a bit type, then the field becomes just that little bit more awkward to manage - though still a good choice if the struct is size-sensitive.

Quoted 6 lines

Because of this, I'd be in favour of just removing the text and then letting the developer choose the best field type for the job. If bool is a
bad choice for a given situation, that should be caught in review.

/Bruce

OK, I'll buy that.

Acked-by on v1 1/1
#5 lore raw
In reply to Maxime Leroy
Quoted 30 lines

-----Original Message-----
From: Maxime Leroy <[email protected]> On Behalf Of Maxime Leroy
Sent: Monday 20 July 2026 12:46
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Thomas Monjalon <[email protected]>; David Marchand <[email protected]>; Maxime Leroy <[email protected]>
Subject: [PATCH] doc: drop recommendation against bool in structures

The coding style advised against bool in structures, citing space and type-size concerns inherited from the Linux kernel. That does not match DPDK practice: bool is already used in over 1400 structure fields across the tree, including core APIs such as rte_flow. Drop the note so the style guide reflects actual usage.

---
 doc/guides/contributing/coding_style.rst | 9 ---------
 1 file changed, 9 deletions(-)
doc/guides/contributing/coding_style.rst +0 -0
index 976a1e1de3..11de3bb39a 100644
@@ -313,15 +313,6 @@ Structure Declarations
 * Use of the structures should be by separate variable declarations and those declarations must be

extern if they are declared in a header file.
* Externally visible structure definitions should have the structure name prefixed by ``rte_`` to
avoid namespace collisions.

-.. note::

doc/guides/contributing/coding_style.rst Structure Declarations · line 324

Quoted 8 lines
doc/guides/contributing/coding_style.rst +0 -8
-
-    Avoid using ``bool`` in structures because it wastes space and
-    the type size is unclear. A preferred use of
-    ``bool`` is mainly as a return type from functions that return true/false,
-    and maybe local variable functions.
-
-    Ref: `LKML <https://lkml.org/lkml/2017/11/21/384>`_
-
Quoted 5 lines

Queues
~~~~~~

--
2.43.0

Acked-by Bruce Richardson Acked-by Morten Brørup Acked-by Marat Khalili on v1 1/1 Applied
#6 lore raw
In reply to Maxime Leroy

20/07/2026 13:46, Maxime Leroy:

Quoted 7 lines

The coding style advised against bool in structures, citing space and type-size concerns inherited from the Linux kernel. That does not match DPDK practice: bool is already used in over 1400 structure fields across the tree, including core APIs such as rte_flow. Drop the note so the style guide reflects actual usage.

Applied, thanks.