Representation clauses in Ada


A record_representation_clause specifies the storage representation of records and record extensions, that is, the order, position, and size of components (including discriminants, if any). ARM12

They are very useful when interfacing with hardware. Doing this in C quickly turns into a mess of bitwise or'ing and bitshifting certain values by certain widths which might be fast, but is hard to read. Here I will try to show how this can be done in a better way in Ada, using representation clauses.

more ...