grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[MULTIBOOT2 DOC PATCH 08/10] multiboot2: Add C structure alignment and p


From: Daniel Kiper
Subject: [MULTIBOOT2 DOC PATCH 08/10] multiboot2: Add C structure alignment and padding consideration section
Date: Thu, 9 Jun 2016 22:30:42 +0200

Signed-off-by: Daniel Kiper <address@hidden>
---
 doc/multiboot.texi |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/doc/multiboot.texi b/doc/multiboot.texi
index c81b2ea..bf02a1b 100644
--- a/doc/multiboot.texi
+++ b/doc/multiboot.texi
@@ -1384,6 +1384,7 @@ document, but are included for prospective operating 
system and boot
 loader writers.
 
 @menu
+* C structure alignment and padding consideration::
 * Notes on PC::                 
 * BIOS device mapping techniques::  
 * Example OS code::             
@@ -1391,6 +1392,22 @@ loader writers.
 @end menu
 
 
address@hidden C structure alignment and padding consideration
address@hidden C structure alignment and padding consideration
+
+Many C compilers try to optimize memory accesses aligning structure
+members properly. Usually they reach the goal by adding some padding.
+This is very useful thing in general. However, if you try to mix assembler
+with C or use C to implement structure low level access this behavior
+may lead, at least, to quite surprising results. Hence, compiler should
+be instructed to not optimize such accesses. Usually it is done by special
+attribute added to structure definition, e.g. GCC compatible sources use
address@hidden ((__packed__))} for this purpose. However, this is not
+required if it is known that its members are properly aligned and compiler
+does not do any optimization. Very good example of this is shown below in
address@hidden file.
+
+
 @node Notes on PC
 @section Notes on PC
 
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]