Next: , Previous: Attribute Safe_Small, Up: Implementation Defined Attributes


4.52 Attribute Scalar_Storage_Order

For every array or record type S, the representation attribute Scalar_Storage_Order 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:

    --  Component type definitions
    
    subtype Yr_Type is Natural range 0 .. 127;
    subtype Mo_Type is Natural range 1 .. 12;
    subtype Da_Type is Natural range 1 .. 31;
    
    --  Record declaration
    
    type Date is record
       Years_Since_1980 : Yr_Type;
       Month            : Mo_Type;
       Day_Of_Month     : Da_Type;
    end record;
    
    --  Record representation clause
    
    for Date use record
       Years_Since_1980 at 0 range 0  ..  6;
       Month            at 0 range 7  .. 10;
       Day_Of_Month     at 0 range 11 .. 15;
    end record;
    
    --  Attribute definition clauses
    
    for Date'Bit_Order use System.High_Order_First;
    for Date'Scalar_Storage_Order use System.High_Order_First;
    --  If Scalar_Storage_Order is specified, it must be consistent with
    --  Bit_Order, so it's best to always define the latter explicitly if
    --  the former is used.

Other properties are as for standard representation attribute Bit_Order, as defined by Ada RM 13.5.3(4). The default is System.Default_Bit_Order.

For a record type T, if T'Scalar_Storage_Order is specified explicitly, it shall be equal to T'Bit_Order. Note: this means that if a Scalar_Storage_Order attribute definition clause is not confirming, then the type's Bit_Order 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 the derived type. For a record extension, the derived type must have the same scalar storage order as the parent type.

If a component of T is of a record or array type, then that type must also have a Scalar_Storage_Order attribute definition clause.

A component of a record or array type that is a packed array, or that does not start on a byte boundary, must have the same scalar storage order as the enclosing record or array type.

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

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

If the opposite storage order is specified, then whenever the value of a scalar component of an object of type S 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:

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 Default_Scalar_Storage_Order.

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