Ada Programming/Attributes/'Scalar Storage Order

Description
For every array or record type, the representation attribute   denotes the order in which storage elements that make up scalar components are ordered within S. The value given must be a static expression of type System.Bit_Order. The following is an example of the use of this feature: Other properties are as for the standard representation attribute  defined by Ada RM 13.5.3(4). The default is.

For a record type, if   is specified explicitly, it shall be equal to. Note: this means that if a  attribute definition clause is not confirming, then the type’s   shall be specified explicitly and set to the same value.

Derived types inherit an explicitly set scalar storage order from their parent types. This may be overridden for the derived type by giving an explicit scalar storage order for it. However, for a record extension, the derived type must have the same scalar storage order as the parent type.

A component of a record type that is itself a record or an array and that does not start and end on a byte boundary must have have the same scalar storage order as the record type. A component of a bit-packed array type that is itself a record or an array must have the same scalar storage order as the array type.

No component of a type that has an explicit  attribute definition may be aliased.

A confirming  attribute definition clause (i.e. with a value equal to  ) has no effect.

If the opposite storage order is specified, then whenever the value of a scalar component of an object of type  is read, the storage elements of the enclosing machine scalar are first reversed (before retrieving the component value, possibly applying some shift and mask operatings on the enclosing machine scalar), and the opposite operation is done for writes.

In that case, the restrictions set forth in 13.5.1(10.3/2) for scalar components are relaxed. Instead, the following rules apply:


 * the underlying storage elements are those at positions
 * the sequence of underlying storage elements shall have a size no greater than the largest machine scalar
 * the enclosing machine scalar is defined as the smallest machine scalar starting at a position no greater than  and covering storage elements at least up to
 * the position of the component is interpreted relative to that machine scalar.

If no scalar storage order is specified for a type (either directly, or by inheritance in the case of a derived type), then the default is normally the native ordering of the target, but this default can be overridden using pragma.

If a component of  is itself of a record or array type, the specfied   does not apply to that nested type: an explicit attribute definition clause must be provided for the component type as well if desired.

Representation changes that explicitly or implicitly toggle the scalar storage order are not supported and may result in erroneous execution of the program, except when performed by means of an instance of.

In particular, overlays are not supported and a warning is given for them:

In most cases, such representation changes ought to be replaced by an instantiation of a function or procedure provided by.

Note that the scalar storage order only affects the in-memory data representation. It has no effect on the representation used by stream attributes.

Note that debuggers may be unable to display the correct value of scalar components of a type for which the opposite storage order is specified.