memory alignment
Q: so when we declare a variable, can it be given an unaligned address, that we have to later fix like this? Great question 👌 — let’s break it down carefully. 🔹 In normal C code (user-space, standard malloc/stack/global variables): The compiler and runtime guarantee that variables are allocated with the correct alignment. Example: int x; // always aligned to 4 bytes on a 32-bit or 64-bit system double y; // usually aligned to 8 bytes You don’t need to “fix” alignment yourself. If the compiler needs padding (inside structs, arrays, etc.), it will add it automatically. So in everyday application code, you’ll never see an int at an odd address unless you deliberately break the rules. 🔹 Where unaligned addresses can happen: Packed data (files, network packets, protocols): struct __ attribute__ (( packed )) Header { char a; int b; // may be at offset 1, unaligned }; If you directly read hdr->b , tha...