[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 24/37] docs/devel/style: add a section about bitfield, and dis
From: |
Alex Bennée |
Subject: |
[PATCH v2 24/37] docs/devel/style: add a section about bitfield, and disallow them for packed structures |
Date: |
Tue, 14 Jan 2025 11:38:08 +0000 |
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Tested-by: Stefan Weil <sw@weilnetz.de>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20250110203401.178532-3-pierrick.bouvier@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
docs/devel/style.rst | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/docs/devel/style.rst b/docs/devel/style.rst
index 2f68b50079..d025933808 100644
--- a/docs/devel/style.rst
+++ b/docs/devel/style.rst
@@ -416,6 +416,26 @@ definitions instead of typedefs in headers and function
prototypes; this
avoids problems with duplicated typedefs and reduces the need to include
headers from other headers.
+Bitfields
+---------
+
+C bitfields can be a cause of non-portability issues, especially under windows
+where `MSVC has a different way to lay them out than GCC
+<https://gcc.gnu.org/onlinedocs/gcc/x86-Type-Attributes.html>`_, or where
+endianness matters.
+
+For this reason, we disallow usage of bitfields in packed structures and in any
+structures which are supposed to exactly match a specific layout in guest
+memory. Some existing code may use it, and we carefully ensured the layout was
+the one expected.
+
+We also suggest avoiding bitfields even in structures where the exact
+layout does not matter, unless you can show that they provide a significant
+usability benefit.
+
+We encourage the usage of ``include/hw/registerfields.h`` as a safe replacement
+for bitfields.
+
Reserved namespaces in C and POSIX
----------------------------------
--
2.39.5
- [PATCH v2 13/37] tests/tcg/plugins/syscall: fix 32-bit build, (continued)
- [PATCH v2 13/37] tests/tcg/plugins/syscall: fix 32-bit build, Alex Bennée, 2025/01/14
- [PATCH v2 33/37] docs/devel: add b4 for patch retrieval, Alex Bennée, 2025/01/14
- [PATCH v2 16/37] contrib/plugins/cache: fix 32-bit build, Alex Bennée, 2025/01/14
- [PATCH v2 11/37] tests/tcg/plugins/insn: remove unused callback parameter, Alex Bennée, 2025/01/14
- [PATCH v2 37/37] scripts/nsis.py: Run dependency check for each DLL file only once, Alex Bennée, 2025/01/14
- [PATCH v2 18/37] contrib/plugins/cflow: fix 32-bit build, Alex Bennée, 2025/01/14
- [PATCH v2 28/37] tests/qtest: fix some copy and paste errors in kdoc, Alex Bennée, 2025/01/14
- [PATCH v2 29/37] include/exec: fix some copy and paste errors in kdoc, Alex Bennée, 2025/01/14
- [PATCH v2 24/37] docs/devel/style: add a section about bitfield, and disallow them for packed structures,
Alex Bennée <=
- [PATCH v2 21/37] configure: reenable plugins by default for 32-bit hosts, Alex Bennée, 2025/01/14
- [PATCH v2 32/37] docs/devel: add git-publish for patch submitting, Alex Bennée, 2025/01/14
- [PATCH v2 19/37] contrib/plugins/hwprofile: fix 32-bit build, Alex Bennée, 2025/01/14
- [PATCH v2 27/37] editorconfig: update for perl scripts, Alex Bennée, 2025/01/14
- [PATCH v2 31/37] docs/sphinx: include kernel-doc script as a dependency, Alex Bennée, 2025/01/14
- [PATCH v2 20/37] contrib/plugins/hotpages: fix 32-bit build, Alex Bennée, 2025/01/14
- [PATCH v2 23/37] win32: remove usage of attribute gcc_struct, Alex Bennée, 2025/01/14
- [PATCH v2 30/37] include/exec: remove warning_printed from MemoryRegion, Alex Bennée, 2025/01/14