On this page
Memory Layout, Alignment & Qualifiers
Prev: Preprocessor & Macros | Up: compilation_and_internals | Next: Error Handling & goto cleanup
Rel: Structs, Unions & Enums, Call Stack & Heap
Ref: cppreference — Alignment
Tags: #public #prog #c #internals #memory
Contents
Inspecting Alignment & Offsets (_Alignof, offsetof)
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
typedef struct {
uint8_t tag; // offset 0 (+3 padding bytes)
uint32_t value; // offset 4
uint64_t ts; // offset 8
} Record;
// sizeof(Record) == 16, offsetof(Record, value) == 4
restrict & volatile
restrict(C99): promises the compiler that two pointer parameters do not alias the same memory (void *memcpy(void *restrict dst, const void *restrict src, size_t n)), enabling vectorization and register caching.volatile: tells the compiler every read/write must hit memory (used for memory-mapped hardware registers and signal flags — not a substitute for<stdatomic.h>thread synchronization).
Linked from
- tuts/c/builtins
- tuts/c/builtins/_Alignof
- tuts/c/builtins/restrict
- tuts/c/builtins/volatile
- tuts/c/compilation_and_internals
- tuts/c/compilation_and_internals/error_handling_and_cleanup
- tuts/c/compilation_and_internals/memory_layout_and_abi
- tuts/c/compilation_and_internals/preprocessor_and_macros
- tuts/c/fundamentals/structs_unions_and_enums
Related notes
- tuts/c/compilation_and_internals Linked here; links to this page; shared tags: #c, #internals, #prog
- tuts/c/compilation_and_internals/error_handling_and_cleanup Linked here; links to this page; shared tags: #c, #internals, #prog
- tuts/c/compilation_and_internals/preprocessor_and_macros Linked here; links to this page; shared tags: #c, #internals, #prog
- tuts/c/fundamentals/structs_unions_and_enums Linked here; links to this page; shared tags: #c, #prog
- tuts/c/builtins links to this page; shared tags: #c, #prog
- tuts/c/builtins/_Alignof links to this page; shared tags: #c, #prog
- tuts/c/builtins/restrict links to this page; shared tags: #c, #prog
- tuts/c/builtins/volatile links to this page; shared tags: #c, #prog
- tuts/programming/memory_and_execution/call_stack_and_heap Linked here; shared tags: #memory, #prog
- tuts/c/compilation_and_internals/build_pipeline_and_linking shared tags: #c, #internals, #prog