mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 21:03:54 -06:00
docs/devel/style: add a section about bitfield, and disallow them for packed structures
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> Message-Id: <20250116160306.1709518-25-alex.bennee@linaro.org>
This commit is contained in:
parent
8f5a4cfc7e
commit
ecbf3567e2
1 changed files with 20 additions and 0 deletions
|
@ -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
|
||||
----------------------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue