Next: Determining the Representations chosen by GNAT, Previous: Address Clauses, Up: Representation Clauses and Pragmas
Normally the specification of a foreign language convention for a type or an object has no effect on the chosen representation. In particular, the representation chosen for data in GNAT generally meets the standard system conventions, and for example records are laid out in a manner that is consistent with C. This means that specifying convention C (for example) has no effect.
There are three exceptions to this general rule:
type Color is (Red, Green, Blue);
8 bits is sufficient to store all values of the type, so by default, objects
of type Color
will be represented using 8 bits. However, normal C
convention is to use 32 bits for all enum values in C, since enum values
are essentially of type int. If pragma Convention C
is specified for an
Ada enumeration type, then the size is modified as necessary (usually to
32 bits) to be consistent with the C convention for enum values.
Fortran has a similar convention for LOGICAL
values (any nonzero
value represents true).
To accommodate the Fortran and C conventions, if a pragma Convention specifies C or Fortran convention for a derived Boolean, as in the following example:
type C_Switch is new Boolean; pragma Convention (C, C_Switch);
then the GNAT generated code will treat any nonzero value as true. For truth values generated by GNAT, the conventional value 1 will be used for True, but when one of these values is read, any nonzero value is treated as True.