notebook/notes/c17/alignment.md

4.0 KiB

title TARGET DECK FILE TAGS tags
Alignment Obsidian::STEM c17 x86-64
c17

Overview

For a large class of modern ISAs, storage for basic C datatypes respect self-alignmnet. This means chars can start on any byte address, shorts on any even address, 4-byte ints and floats must start on an address divisible by 4, and doubles must start on an address divisible by 8. Likewise pointers are also self-aligned.

%%ANKI Basic What does self-alignment refer to? Back: The placement of C datatypes on an address divisible by the size of the datatype. Reference: Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.

END%%

%%ANKI Basic What addresses can a char be stored at? Back: Any address. Reference: Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.

END%%

%%ANKI Basic What addresses can a int be stored at? Back: Any address divisible by 4. Reference: Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.

END%%

%%ANKI Basic What addresses can a short be stored at? Back: Any address divisible by 2. Reference: Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.

END%%

%%ANKI Basic What addresses can a double be stored at? Back: Any address divisible by 8. Reference: Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.

END%%

%%ANKI Basic What addresses can a pointer be stored at? Back: Any address divisible by 8. Reference: Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.

END%%

%%ANKI Basic How does self-alignment make access faster? Back: It enables single instruction fetches and puts. Reference: Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.

END%%

%%ANKI Cloze With respect to memory alignment, {slop} is {waste space for padding datatypes to their alignment}. Reference: Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.

END%%

%%ANKI Basic What value is slop initialized to? Back: Undefined. Reference: Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.

END%%

%%ANKI Basic Why isn't equality for structs well-defined? Back: The value of slop is undefined. Reference: Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.

END%%

%%ANKI Basic Why isn't inequality for structs well-defined? Back: The value of slop is undefined. Reference: Raymond, Eric. “The Lost Art of Structure Packing.” Accessed November 4, 2024. http://www.catb.org/esr/structure-packing/.

END%%

Bibliography