Anonymous user
Ada: Difference between revisions
Jump to navigation
Jump to search
→Representation clauses
[unchecked revision] | [unchecked revision] |
m (→Features) |
|||
Line 41:
=== Representation clauses ===
Ada allows for explicitly defining the in-memory representation of scalar and compound types. The following example demonstrates the definition of
<source lang="ada">
----------------------------------------------------------------------------▼
-- The format of the System Table Descriptor pointer used by the processor▼
-- to load descriptor tables like the GDT and IDT.▼
----------------------------------------------------------------------------▼
type System_Table_Descriptor is▼
record▼
Size : Unsigned_16;▼
Offset : System.Address;▼
end record▼
with Size => 48;▼
for System_Table_Descriptor use▼
record▼
Size at 0 range 0 .. 15;▼
Offset at 0 range 16 .. 47;▼
end record;▼
</source>
The <tt>Size</tt> ''aspect specifier'' instructs the compiler that the <tt>System_Table_Descriptor</tt> type must be 48 bits in size. The ''record representation clause'' instructs the compiler as to the required layout of this record type in memory. This example specifies that the <tt>Size</tt> member should occupy bits 0 to 15, and the <tt>Offset</tt> member should occupy bits 16 to 47. This feature is analogous to C's bit-fields.
The following example demonstrates defining the in-memory representation of an enumerated type.
<source lang="ada">
Line 62 ⟶ 84:
Ring_3 => 3
);
▲ ----------------------------------------------------------------------------
▲ -- The format of the System Table Descriptor pointer used by the processor
▲ -- to load descriptor tables like the GDT and IDT.
▲ ----------------------------------------------------------------------------
▲ type System_Table_Descriptor is
▲ record
▲ Size : Unsigned_16;
▲ Offset : System.Address;
▲ end record
▲ with Size => 48;
▲ for System_Table_Descriptor use
▲ record
▲ Size at 0 range 0 .. 15;
▲ Offset at 0 range 16 .. 47;
▲ end record;
</source>
The <tt>Size</tt> ''aspect specifier'' instructs the compiler that the <tt>
==See Also==
|