Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It means that the address being pointed at is evenly divisible by some factor.</p> <p>Sometimes the term "natural alignment" is used, which generally means that objects having natural alignment need to be placed at addresses that are evenly divisble by the object's size.</p> <p>Alignment is somestimes very important, since many hardware-related things place restrictions on such alignment.</p> <p>For instance, on the classic <a href="http://en.wikipedia.org/wiki/SPARC" rel="noreferrer">SPARC</a> architecture (and also on classical <a href="http://en.wikipedia.org/wiki/ARM_architecture" rel="noreferrer">ARM</a>, I think), you can't read an integer larger than one byte from an odd address. Trying to do so will immediately halt your program with a bus error. On the x86 architecture, the CPU hardware instead handles the problem (by doing multiple accesses to cache and/or memory as needed), although it might take longer. RISC:ier architectures typically don't do this for you.</p> <p>Things like these can also affect padding, i.e. the insertion of dummy data between e.g. structure fields in order to maintain alignment. A structure like this:</p> <pre><code>struct example { char initial; double coolness; }; </code></pre> <p>would very likely end up having 7 bytes of padding between the fields, to make the <code>double</code> field align on an offset divisible by its own size (which I've assumed to be 8).</p> <p>When viewed in binary, an address aligned to <em>n</em> bytes will have its log2(<em>n</em>) least-significant bits set to zero. For instance, an object that requires 32-byte alignment will have a properly-aligned address that ends with (binary) 00000, since log2(32) is 5. This also implies that an address can be forced into alignment by clearing the required number of bits.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload