On this page
  1. Memory Layout, Alignment & Qualifiers
  2. Contents
  3. Inspecting Alignment & Offsets (_Alignof, offsetof)
  4. restrict & volatile

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

Linked from

Related notes