# Ada Libraries and Attributes

The current, editable version of this book is available in Wikibooks, the open-content textbooks collection, at
https://en.wikibooks.org/wiki/Ada_Libraries_and_Attributes

# Aspects
## Description

Mechanism to define user-defined aggregates.

## Description

Specifying the aspect No_Return indicates that a procedure cannot return normally; it may raise an exception, loop forever, or terminate the program.
A non-returning procedure may not contain any return statements. If a non-returning procedure implicitly returns (by reaching the end of its statement sequence), Program_Error will be raised at the point of call.
On the call site, this enables detection of dead code and suppression of warnings about missing return statements or missing assignment to variables.

## Portability

The aspect No_Return was introduced in Ada 2012. It is the replacement for pragma No_Return which was introduced in Ada 2005.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Aspects
* Ada Programming/Subprograms

### Ada Reference Manual

* 6.5.1: "Non Returning Procedures"

## References

* ↑ AI05-0229
* ↑ AI95-00329
When entities like variables or subprograms are declared, certain properties thereof normally are left to the compiler to specify (like the size or the address of a variable, the calling convention of a subprogram). Properties which may be queried are called Attributes; those which may be specified are called Aspects. Some aspects correspond with attributes which then have the same name. Aspects and attributes are defined in the Ada Reference Manual Annex K: Language-Defined Aspects and Attributes, pragmas in Annex L: Language-Defined Pragmas.

## Description

This language feature has been introduced in Ada 2012.
Aspects are certain properties of an entity that may be specified, depending on the kind of entity, by an aspect specification as part of its declaration or by a separate attribute definition clause or pragma declaration.
If an aspect is not specified, it depends on the aspect itself whether its value is left to the compiler or prescribed in the Ada RM.
The specification of a Boolean valued aspect may omit the aspect definition, which then has the value True.
Examples of such properties are the size of a type, i.e. the number of bits a stand-alone object of that type will use; or that a subprogram will not return from its call: aspect No_Return. This latter one is an example of an aspect that has a Boolean value.

## List of language defined aspects

If not marked otherwise, an aspect is specified by an Aspect_Specification.
An aspect marked Ada 2012 is an Ada 2012 language functionality not available in previous Ada generations.
An aspect marked Ada 2022 is an Ada 2022 language functionality not available in previous Ada generations.
Aspects not so marked, were previously defined via pragmas or attribute definition clauses. This is still possible, but deprecated.

### A – D

* Aggregate (Ada 2022; Aspect_Specification)
* Address (Attribute_Definition_Clause, Aspect_Specification)
* Alignment (Attribute_Definition_Clause)
* All_Calls_Remote (Pragma)
* Allows_Exit (Ada 2022; Aspect_Specification)
* Asynchronous
* Atomic
* Atomic_Components
* Attach_Handler
* Bit_Order (Attribute_Definition_Clause)
* Coding (Enumeration_Representation_Clause)
* Component_Size (Attribute_Definition_Clause)
* Constant_Indexing (Ada 2012)
* Convention
* CPU (Ada 2012)
* Default_Component_Value (Ada 2012)
* Default_Initial_Condition (Ada 2022; Aspect_Specification)
* Default_Iterator (Ada 2012)
* Default_Storage_Pool (Ada 2012; Pragma)
* Default_Value (Ada 2012)
* Dispatching (Ada 2022; Aspect_Specification)
* Dispatching_Domain (Ada 2012)
* Discard_Names (Ada 2012; Aspect_Specification, Pragma)
* Dynamic_Predicate (Ada 2012)

### E – O

* Elaborate_Body (Pragma)
* Exclusive_Functions (Ada 2012)
* Export
* External_Name
* External_Tag (Attribute_Definition_Clause)
* Full_Access_Only (Ada 2022; Aspect_Specification)
* Global (Ada 2022; Aspect_Specification)
* Global'Class (Ada 2022; Aspect_Specification)
* Implicit_Dereference (Ada 2012)
* Import
* Independent (Ada 2012)
* Independent_Components (Ada 2012)
* Inline
* Input (Attribute_Definition_Clause)
* Input'Class (Ada 2012; Attribute_Definition_Clause)
* Integer_Literal (Ada 2022; Aspect_Specification)
* Interrupt_Handler
* Interrupt_Priority
* Iterator_Element (Ada 2012)
* Iterator_View (Ada 2022; Aspect_Specification)
* Layout (Record_Representation_Clause)
* Link_Name
* Machine_Radix (Attribute_Definition_Clause)
* Max_Entry_Queue_Length (Ada 2022; Aspect_Specification)
* No_Controlled_Parts (Ada 2022; Aspect_Specification)
* No_Return
* Nonblocking (Ada 2022; Aspect_Specification)
* Output (Attribute_Definition_Clause)
* Output'Class (Ada 2012; Attribute_Definition_Clause)

### P – Z

* Pack
* Parallel_Calls (Ada 2022; Aspect_Specification)
* Parallel_Iterator (Ada 2022; Aspect_Specification)
* Post (Ada 2012)
* Post'Class (Ada 2012)
* Pre (Ada 2012)
* Pre'Class (Ada 2012)
* Predicate_Failure (Ada 2012)
* Preelaborate (Pragma)
* Preelaborable_Initialization (Ada 2022; Aspect_Specification)
* Priority
* Pure (Pragma)
* Put_Image (Ada 2022; Aspect_Specification)
* Read (Attribute_Definition_Clause)
* Read'Class (Ada 2012; Attribute_Definition_Clause)
* Real_Literal (Ada 2022; Aspect_Specification)
* Relative_Deadline (Ada 2022; Aspect_Specification)
* Remote_Call_Interface (Pragma)
* Remote_Types (Pragma)
* Shared_Passive (Pragma)
* Size (Attribute_Definition_Clause)
* Small (Attribute_Definition_Clause)
* Stable_Properties (Ada 2022; Aspect_Specification)
* Stable_Properties'Class (Ada 2022; Aspect_Specification)
* Static (Ada 2022; Aspect_Specification)
* Static_Predicate (Ada 2012)
* Storage_Pool (Attribute_Definition_Clause)
* Storage_Size (Attribute_Definition_Clause)
* Stream_Size (Attribute_Definition_Clause)
* String_Literal (Ada 2022; Aspect_Specification)
* Synchronization (Ada 2012)
* Type_Invariant (Ada 2012)
* Type_Invariant'Class (Ada 2012)
* Unchecked_Union (Ada 2022; Aspect_Specification)
* Use_Formal (Ada 2022; Aspect_Specification)
* Variable_Indexing (Ada 2012)
* Volatile
* Volatile_Components
* Write (Attribute_Definition_Clause)
* Write'Class (Ada 2012; Attribute_Definition_Clause)
* Yield (Ada 2022; Aspect_Specification)

## List of implementation defined aspects

The following pragmas are not available in all Ada compilers, only in those that had implemented them.
Currently, there are only listed the implementation-defined pragmas of a few compilers. You can help Wikibooks adding specific aspects of other compilers:

### GNAT

    Implementation defined aspect of the GNAT compiler from AdaCore and FSF.
* Ada_2005 (GNAT)
* Ada_2012 (GNAT)
* Favor_Top_Level (GNAT)
* Inline_Always (GNAT)
* Object_Size (GNAT)
* Persistent_BSS (GNAT)
* Pure_Function (GNAT)
* Remote_Access_Type (GNAT)
* Shared (GNAT)
* Suppress_Debug_Info (GNAT)
* Test_Case (GNAT)
* Universal_Aliasing (GNAT)
* Unmodified (GNAT)
* Unreferenced (GNAT)
* Unreferenced_Objects (GNAT)
* Value_Size (GNAT)
* Warnings (GNAT)

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Keywords
* Ada Programming/Pragmas

### Ada Reference Manual
#### Ada 2012

* 13.1.1: Aspect Specifications
* K.1: Language-Defined Aspects
* J.15: Aspect-related Pragmas

#### Ada 2022

* 13.1.1: Aspect Specifications
* K.1: Language-Defined Aspects
* J.15: Aspect-related Pragmas

## References
# Ada Programming/Aspects/Aggregate
## Description

Mechanism to define user-defined aggregates.

# Ada Programming/Aspects/No Return
## Description

Specifying the aspect No_Return indicates that a procedure cannot return normally; it may raise an exception, loop forever, or terminate the program.
A non-returning procedure may not contain any return statements. If a non-returning procedure implicitly returns (by reaching the end of its statement sequence), Program_Error will be raised at the point of call.
On the call site, this enables detection of dead code and suppression of warnings about missing return statements or missing assignment to variables.

## Portability

The aspect No_Return was introduced in Ada 2012. It is the replacement for pragma No_Return which was introduced in Ada 2005.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Aspects
* Ada Programming/Subprograms

### Ada Reference Manual

* 6.5.1: "Non Returning Procedures"

## References

* ↑ AI05-0229
* ↑ AI95-00329

# Ada Programming/Attributes/'Abort Signal
## Description

Provides the entity for the special exception used to signal task abort or asynchronous transfer of control. Normally this attribute should only be used in the tasking runtime (it is highly peculiar, and completely outside the normal semantics of Ada, for a user program to intercept the abort exception).

## Example

Standard'Abort_Signal (Standard is the only allowed prefix).

# Ada Programming/Attributes/'Access
## Description

X'Access is an Ada attribute where X is any object or subprogram.
'Access may be used to return an access value designating the object or subprogram.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Types/access

### Ada Reference Manual

* 3.10 Access Types (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Address
## Attribute Definition Clause

X'Address is an Ada attribute where X is any object, program unit, or label, RM 13.3(10/1). [A program unit is either a package, a task unit, a protected unit, a protected entry, a generic unit, or an explicitly declared subprogram other than an enumeration literal, RM 10.1(1).]
'Address may be used to return the address of the first element allocated to X. 'Address may also be used to set the address of X for stand-alone objects and program units, RM 13.3(12).
It's not recommended to use Integer_32 in this case.

## Aspect Specification

The address may also be specified directly when declaring the variable using an aspect declaration:

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Alignment

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Address Size
## Description

Is a static constant giving the number of bits in an Address. It is the same value as System.Address’Size, but has the advantage of being static, while a direct reference to System.Address’Size is nonstatic because Address is a private type.

## Example

Standard'Address_Size (Standard is the only allowed prefix)

# Ada Programming/Attributes/'Adjacent
## Description

S'Adjacent(X, T) is an Ada attribute where X is any floating point type.
'Adjacent returns the adjacent floating point number to X in the direction of T.

## Example

The output with GNAT 4.6 on the x86-64 architecture is:

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes

### Ada Reference Manual

* 5.3 Attributes of Floating Point Types (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Aft

S'Aft is an Ada attribute where S is a fixed point subtype.
S'Aft returns the number digits needed after the decimal point to accommodate the precision of the subtype S, unless the delta of the subtype S is larger than 0.1, in which case the attribute returns a value of 1.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes

### Ada Reference Manual

* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Alignment
## Description

X'Alignment is an Ada attribute where X is any memory-allocated object or type. This attribute controls the address values used for objects. The alignment must be non-negative. A value of zero means that the object need not be allocated at the boundary of a storage units. Otherwise the address is a multiple of X's alignment.
The alignment of an object may be set.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Address

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Asm Input
## Description

The Asm_Input attribute denotes a function that takes two parameters. The first is a string, the second is an expression of the type designated by the prefix. The first (string) argument is required to be a static expression, and is the constraint for the parameter, (e.g., what kind of register is required). The second argument is the value to be used as the input argument. The possible values for the constant are the same as those used in the RTL, and are dependent on the configuration file used to built the GCC back end.

## Example
# Ada Programming/Attributes/'Asm Output
## Description

The Asm_Output attribute denotes a function that takes two parameters. The first is a string, the second is the name of a variable of the type designated by the attribute prefix. The first (string) argument is required to be a static expression and designates the constraint for the parameter (e.g., what kind of register is required). The second argument is the variable to be updated with the result. The possible values for constraint are the same as those used in the RTL, and are dependent on the configuration file used to build the GCC back end. If there are no output operands, then this argument may either be omitted, or explicitly given as No_Output_Operands.

## Example
# Ada Programming/Attributes/'Atomic Always Lock Free
## Description

The prefix of the Atomic_Always_Lock_Free attribute is a type. The result indicates whether atomic operations are supported by the target for the given type.

# Ada Programming/Attributes/'Base
## Description

Represents the base type of another type or subtype. This attribute is used to access attributes of the base type.
T'Base refers to the "base range" of the type, which defines the range in which intermediate calculations are performed.

## Base for Integer Types

The standard states that the range of T'Base:
* includes the value 0
* is symmetric about zero, with possibly an extra negative value
* includes all of the values in the subtype T
So for example, if T is:
then the compiler will choose a hardware supported type that includes this range, in this case probably an eight bit type (on a two's complement machine)
This definition is not to be taken literally, as by Ada semantics, T and T'Base would be incompatible. In effect, the declaration of T would then be
Note that built-in operators go through the base type, and T's "+" op for example is implicitly declared as:
There are no constraint checks on T'Base, so for example:
then in the first assignment to O1, there is a constraint check to ensure that the result of 1 + 2 is in the range of T, but in the second assignment to O2, there is no check.
T'Base is useful for generics, when you need to be able to recover the base range of the type, in order to declare an object with value 0; for example, if this is an accumulator.
It is helpful to know something about the base range of the type, so that you have a guarantee that you don't get any overflow during intermediate calculations. For example, given type T above then:
This is a problem, since if the sum of O1 and O2 is large (that is, greater than T'Base'Last), then you'll get overflow. Knowing that you're going to be adding two values together means you should declare the type this way:
That way you know that (sub)type T's range is 1 .. 42, but you also have a guarantee that T'Base'Last >= 84, and hence the sum of two values of type T cannot overflow.
Note that a declaration of the form:
actually declares a subtype, named T, of some anonymous base type. We can refer to the range of this base type as T'Base.

## Base for Enumeration Types

An enumeration type is its own base type, so given this type:
then the range of ET is the same as the range of ET'Base. If you need some extra literals in your "base" type, then you have to declare them manually, not unlike what we did above:
Now you can say ET'Succ (ET'Last) and you'll get a meaningful answer. This is necessary when you do something like:
Also when you derive from ET_Base with a range constraint, the base of the derived type will include all values of the base type:
Note that here ET_BASE_First is of type New_ET.

## Example

If you declare:
and
then Sub_Enum'Base'Last is Enum3.

## See also
### Wikibook

* Ada Programming

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Bit
## Description

obj'Bit, where obj is any object, yields the bit offset within the storage unit (byte) that contains the first bit of storage allocated for the object. The value of this attribute is of the type universal_integer and is always a nonnegative number smaller than System.Storage_Unit.
For an object that is a variable or a constant allocated in a register, the value is zero. (The use of this attribute does not force the allocation of a variable to memory).
For an object that is a formal parameter, this attribute applies to either the matching actual parameter or to a copy of the matching actual parameter.
For an access object the value is zero. Note that obj.all'Bit is subject to an Access_Check for the designated object. Similarly for a record component X.C'Bit is subject to a discriminant check and X(I).Bit and X(I1..I2)'Bit are subject to index checks.
This attribute is designed to be compatible with the DEC Ada 83 definition and implementation of the Bit attribute.

## Example
# Ada Programming/Attributes/'Bit Order
## Description

R'Bit_Order is a representation attribute used to specify the bit numbering of a record representation clause (for a record type). The bit ordering is of type System.Bit_Order, and may be either:
* High_Order_First when the bit 0 is the most significant bit
* Low_Order_First when the bit 0 is the least significant bit
assuming the bit sequence is interpreted as an integer value. The constant System.Default_Bit_Order represents the native bit numbering of the platform.
It is worth noting that the bit ordering only affects the bit numbering for a record representation clause, and not the byte order of its (multibyte) fields.

## Introduction

Storage units are ordered by their addresses. Let's look at an integer occupying several bytes (let's assume a byte being 8 bits for this discussion).
* On a big endian (BE) machine, the integer's most significant byte is stored at the least address.
* On a little endian (LE) machine, its least significant byte is stored at the least address.
So in order to be able to count bits consecutively across byte boundaries, Ada counts bits within a byte according to the endianness from most significant bit (MSB) 0 to least significant bit (LSB) on BE and the other way round on LE.
This is how it looks (conveniently writing left to right on BE, right to left on LE):
We're used to writing left to right, but for LE, as you can see, it's convenient to write addresses from right to left. So on BE, a sequence of bytes and bits is counted like this:
In order to be able to write and count consecutively on LE, we have to write right to left like for example in the Arabian or Hebrew scripts (the MSB is always on the left; this seems to be a global trait in all modern scripts):
In a record representation like the following (of course only one of the two lines specifying X may be present)
the component X occupies the bits shown in boldface. The byte number (0 resp. is 1) is called Position, the bounds are called First_Bit (13 resp. 5) and Last_Bit (17 resp. 9); there are corresponding attributes 'Position, 'First_Bit and 'Last_Bit. (The meaning of the component X is irrelevant here, only its size is relevant.) As you can see, X is a crossborder component. Thus the result of applying the attribute 'Bit_Order to a record with crossborder components depends on the Ada generation.

## Ada 95

Ada 95 defines the result of the attribute for the non-native bit order only when applied within a storage unit or when an item completely fills a sequence of storage units. By applying the attribute to a record, we force the compiler to count bits in the indicated manner, independent of the machine architecture.
The component B occupies the bits shown in boldface:
The layout of this record will be the same on BE and on LE machines, i.e. the representation is endian-independent.
We could equally well have defined this record like so and arrived at the same endian-independent layout:
However a record like the following, where B is crossborder, is only valid on a BE machine, i.e. in the native bit order.
Compiled on a LE machine, the compiler will complain that B occupies non-contiguous storage and reject the code, since the byte order is not affected by the attribute (remember, the next byte with bit numbers 8 to 15 has to be put on the left):
As an example of a record where items fill a range of complete storage units take:
This is valid on both architectures leading to the layout:
where A fills the bits in normal face, B those in bold face. As you can see, it doesn't matter that bits are counted in this strange way on LE since component B fills its two bytes completely.

## Ada 2005

For the native bit order, there is no change. Record representation specifications have worked since Ada 83. Only the attribute 'Bit_Order has been introduced in Ada 95 with the restrictions as shown above.
In order to improve the situation for non-native bit orders, Ada 2005 introduces the notion of machine scalars. A machine scalar is a conceptual hardware based unsigned integer within which bits are counted and the components positioned as requested.
We need a more elaborated record example now (the values returned by the corresponding attributes 'Position, 'First_ and 'Last_Bit (in native bit order) are given as comments; note that the bit numbers returned are always counted starting with the byte in which the component begins):
Let's assume I is a 16 bit (signed or unsigned) integer, the other components are of some unspecified types with the given size requirements. The complete record's size is 48. This is how it looks like on BE and LE machines:
In the following, we're going to show how far we can go to reach endian-independence of the representation. The result will be that we only have to swap bytes after transfer from one architecture to the other when the new Ada 2005 features are used correctly.
For the following, we'll assume that we are on a big-endian machine, so that we append the corresponding attribute to the representation:
When this is compiled on a little-endian machine, all components with the same Position are taken together and put in a matching machine scalar. The machine scalar is positioned at the given Position, but inside the bits are counted from the opposite side.
Let's take the first component, I. It uses 16 bits, so a 16 bit machine scalar will do. It is positioned at byte 0, but inside the compiler will count from the high order bit side. This is how it looks (NNBO - non-native bit order):
Now to the next Position 2. The respective components A, B, C use together three bytes, so a 32 bit machine scalar is needed. It is positioned at byte 2, and inside the count will again start from the opposite side. This is how it looks:
The bit count starts at the high order bit of byte 5 and continues down to the low order bit of byte 2. The components A, B, C are positioned inside this scalar according to the respective ranges. Thus we arrive at this layout:
We immediately see the conflict with component D, whose range is already occupied by A, and the compiler will of course complain and reject the code. The solution is simple: Just instead of locating D at Position 5, we change this to the (on BE) equivalent line like so:
And, drum roll, on LE, we now have (for comparison, the native layout is also given):
In the non-native bit order, the values returned by the corresponding attributes 'Position, 'First_ and 'Last_Bit are exactly those given in the record specification.
As an additional service, GNAT's compilation output will give you the values as counted in the native bit order within the machine scalar:
This is as far as we can get with the current Ada standard.

## Data Transfer

Let us transfer a value of this record from the native big-endian machine to a little-endian machine. For demonstration purposes, the high-order parts of the crossborder items are shown in upper case, the low-order parts in lower case.
The bytes will be transferred in the given order. Since the bit order attribute does not reorder the bytes after transfer, on the target machine we will receive the data in scrambled order:
All we have to do to arrive at the desired end, is to swap bytes 0↔1, 2↔5, 3↔4:

## Example

The following two sets of representation clauses specify the same register layout in any machine / compiler (Ada 2005 and later):
If the bit order is modified, the bit numbering of all the elements of the record representation clause must be reversed:
Both can be interchangeably used in the same machine. But note that in two machines with different endianness the Data field will have the native byte order regardless of the bit order specified in the representation clauses.

## Incorrect Usage

The 'Bit_Order attribute is not intended to convert data between a big-endian and a little-endian machine (it affects bit numbering, not byte order). The compiler will not generate code to reorder multi-byte fields when a non-native bit order is specified.

## References

* ↑ Note that when the ARM talks about "big endian" and "little endian" in the definition of the 'Bit_Order attribute it really means bit endianness, not byte endianness. (Nowadays the term endianness is usually reserved for talking about byte order, although it can also be used for bit numbering.) Thus, in this context, when the ARM says "little endian" it refers to "LSB 0", and when it says "big endian" this is the same as "MSB 0": «High_Order_First (known in the vernacular as “big endian”) means that the first bit of a storage element (bit 0) is the most significant bit (interpreting the sequence of bits that represent a component as an unsigned integer value). Low_Order_First (known in the vernacular as “little endian”) means the opposite: the first bit is the least significant.»
* ↑ ISO/IEC 8652:1987. "13.4 Record Representation Clauses". Ada 83 Reference Manual. The range defines the bit positions of the storage place, relative to the storage unit. The first storage unit of a record is numbered zero. The first bit of a storage unit is numbered zero. The ordering of bits in a storage unit is machine_dependent and may extend to adjacent storage units. {{cite book}}: Unknown parameter |chapterurl= ignored (|chapter-url= suggested) (help)
* ↑ AI95-00133-01 (1996-05-07). "Controlling bit ordering". Class: binding interpretation. Ada Rapporteur Group. Bit_Order clauses are concerned with the numbering of bits and not concerned with data flipping interoperability.
* ↑ ISO/IEC 8652:2007. "13.5.3 Bit Ordering (9/2)". Ada 2005 Reference Manual. Retrieved 2008-06-02. Bit_Order clauses make it possible to write record_representation_clauses that can be ported between machines having different bit ordering. They do not guarantee transparent exchange of data between such machines. {{cite book}}: Unknown parameter |chapterurl= ignored (|chapter-url= suggested) (help)
* ↑ Thomas Quinot (2013). "Gem #140: Bridging the Endianness Gap". AdaCore. Retrieved 2013-01-31. the order in which the bytes that constitute machine scalars are written to memory is not changed by the Bit_Order attribute -- only the indices of bits within machine scalars are changed. {{cite web}}: Unknown parameter |month= ignored (help)

## Interfacing

Record representation clauses are a unique feature of the Ada language as far as the authors know, so there is no need to have a feature similar to attribute 'Bit_Order in other programming languages. It is common practice in other programming languages to use masks and bit operations explicitly, thus the native bit numbering must always be used.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Position
* 'First_Bit
* 'Last_Bit

### Ada Reference Manual

* 13.5.3 Bit Ordering (Annotated)
* Annex K Language-Defined Attributes (Annotated)

### Ada Rationale

* Ada 95: 13.1 Representation of Data
* Ada 2005: 9.2.1 Incompatibilities with original Ada 95

## Further reading

* Norman H. Cohen (1994). "Endian-independent record representation clauses" (PDF). ACM SIGAda Ada Letters. New York, NY, USA: Association for Computing Machinery. XIV (1): 27–29. ISSN 1094-3641. Retrieved 2008-12-20.
* Randal P. Andress (2005). "Wholesale byte reversal of the outermost Ada record object to achieve endian independence for communicated data types" (PDF). ACM SIGAda Ada Letters. New York, NY, USA: Association for Computing Machinery. XXV (3): 19–27. ISSN 1094-3641. Retrieved 2008-12-20.

# Ada Programming/Attributes/'Bit Order:3

The 'Bit_Order attribute is not intended to convert data between a big-endian and a little-endian machine (it affects bit numbering, not byte order). The compiler will not generate code to reorder multi-byte fields when a non-native bit order is specified.

## References

* ↑ AI95-00133-01 (1996-05-07). "Controlling bit ordering". Class: binding interpretation. Ada Rapporteur Group. Bit_Order clauses are concerned with the numbering of bits and not concerned with data flipping interoperability.
* ↑ ISO/IEC 8652:2007. "13.5.3 Bit Ordering (9/2)". Ada 2005 Reference Manual. Retrieved 2008-06-02. Bit_Order clauses make it possible to write record_representation_clauses that can be ported between machines having different bit ordering. They do not guarantee transparent exchange of data between such machines. {{cite book}}: Unknown parameter |chapterurl= ignored (|chapter-url= suggested) (help)
* ↑ Thomas Quinot (2013). "Gem #140: Bridging the Endianness Gap". AdaCore. Retrieved 2013-01-31. the order in which the bytes that constitute machine scalars are written to memory is not changed by the Bit_Order attribute -- only the indices of bits within machine scalars are changed. {{cite web}}: Unknown parameter |month= ignored (help)

# Ada Programming/Attributes/'Bit Position
## Description

R.C'Bit_Position, where R is a record object and C is one of the fields of the record type, yields the bit offset within the record contains the first bit of storage allocated for the object. The value of this attribute is of the type universal_integer. The value depends only on the field C and is independent of the alignment of the containing record R.

## Example
# Ada Programming/Attributes/'Body Version
## Description

Yields a value of the predefined type String that identifies the version of the compilation unit (P) that contains the body (but not any subunits) of the program unit.

## Example
# Ada Programming/Attributes/'Callable
## Description

X'Callable is an Ada attribute where X is any task object. If the task is completed or has been terminated, this attribute is false. Otherwise, this attribute is true (i.e. the task is callable).
Be warned - calling X'Callable can result in a race condition. X'Callable may be true at the time the attribute value is read, but it may become false at the time action is taken based on the value read. Once X'Callable is false, however, it can be expected to stay false.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Terminated

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Caller
## Description

Identifies the task whose call is now being serviced. Yields a value of the type Task_Id that identifies the task whose call is now being serviced.
Use of this attribute is allowed only inside an accept_statement, or entry_body after the entry_barrier, corresponding to the entry_declaration denoted by E.

## Example
# Ada Programming/Attributes/'Ceiling
## Description

X'Ceiling(Y) is an Ada attribute where X is any floating-point type and Y is any instance of that type. This attribute represents the smallest integer value that is greater than or equal to Y.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Floor
* Ada Programming/Attributes/'Rounding
* Ada Programming/Attributes/'Unbiased_Rounding

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Class

The Class attribute denotes the class wide type of the given tagged type.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Object Orientation
* Ada Programming/OO

### Ada Reference Manual

* 3.9 Tagged Types and Type Extensions (Annotated)
* 7.3.1 Private Operations (Annotated)

# Ada Programming/Attributes/'Code Address
## Description

The 'Address attribute may be applied to subprograms in Ada 95 and Ada 2005, but the intended effect seems to be to provide an address value which can be used to call the subprogram by means of an address clause as in the following example:
A call to L is then expected to result in a call to K. In Ada 83, where there were no access-to-subprogram values, this was a common work-around for getting the effect of an indirect call. GNAT implements the above use of Address and the technique illustrated by the example code works correctly.
However, for some purposes, it is useful to have the address of the start of the generated code for the subprogram. On some architectures, this is not necessarily the same as the Address value described above. For example, the Address value may reference a subprogram descriptor rather than the subprogram itself.
The 'Code_Address attribute, which can only be applied to subprogram entities, always returns the address of the start of the generated code of the specified subprogram, which may or may not be the same value as is returned by the corresponding 'Address attribute.

## Example
# Ada Programming/Attributes/'Compiler Version
## Description

Standard'Compiler_Version (Standard is the only allowed prefix) yields a static string identifying the version of the compiler being used to compile the unit containing the attribute reference.

# Ada Programming/Attributes/'Component Size
## Description

R'Component_Size is a representation attribute used to get the number of bits of each component of an array object or type.
The 'Component_Size attribute may also be used in representation clauses to specify the size in bits used to store each component of an array type.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Size
* Ada Programming/Attributes/'Max_Size_In_Storage_Elements
* Ada Programming/Attributes/'Value_Size (implementation defined)
* Ada Programming/Attributes/'Object_Size (implementation defined)

### Ada 95 Reference Manual

* 13.3: Operational and Representation Attributes
* Annex K: Language-Defined Attributes

### Ada 2005 Reference Manual

* 13.3: Operational and Representation Attributes
* Annex K: Language-Defined Attributes

# Ada Programming/Attributes/'Compose
## Description

X'Compose(Fraction : X, Exponent : Integer) is an Ada attribute where X is any floating point type.
Floating point types are represented as:
    $sign\times mantissa\times radix^{exponent}$
where
    sign is 1 or -1
    mantissa is a fraction in base radix
    radix is the hardware radix (usually 2)
    exponent is an integer
'Compose(Fraction, Exponent) returns the floating point number Fraction with the exponent replaced with Exponent.

## Example

The output with GNAT 4.6 on the x86-64 architecture is:

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Fraction

### Ada Reference Manual

* 5.3 Attributes of Floating Point Types (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Constrained
## Description

True if A of discriminated type denotes a constant, a value, or a constrained variable.
Yields the value True if A denotes a constant, a value, a tagged object, or a constrained variable, and False otherwise.
The value of this attribute is of the predefined type Boolean.

## Example
# Ada Programming/Attributes/'Copy Sign
## Description

S'Copy_Sign(X, Y) is an Ada attribute where S is any floating-point type, and X and Y are any instance of that type. This attribute represents the floating point value with the magnitude of X and the sign of Y.
If the resulting value is outside the base range of S, a Constraint_Error exception is raised.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes

### Ada Reference Manual

* A.5.3 Attributes of Floating Point Types (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Count
## Description

X'Count is an Ada attribute where X is an entry point in a protected type. This attribute returns the number of tasks currently enqueued waiting for entrance into the entry procedure.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Tasking

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Default Bit Order
## Description

Standard'Default_Bit_Order (Standard is the only allowed prefix), provides the value System.Default_Bit_Order as a Pos value (0 for High_Order_First, 1 for Low_Order_First). This is used to construct the definition of Default_Bit_Order in package System.

# Ada Programming/Attributes/'Default Scalar Storage Order
## Description

Standard'Default_Scalar_Storage_Order (Standard is the only allowed prefix), provides the current value of the default scalar storage order (as specified using pragma Default_Scalar_Storage_Order, or equal to Default_Bit_Order if unspecified) as a System.Bit_Order value. This is a static attribute.

# Ada Programming/Attributes/'Definite
## Description

S'Definite yields True if the actual subtype corresponding to S is definite; otherwise, it yields False.
The value of this attribute is of the predefined type Boolean.

## Example
# Ada Programming/Attributes/'Delta
## Description

X'Delta is an Ada attribute where X is any fixed point type. This attribute represents the delta specified in the type definition of X.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Types/delta
* Ada Programming/Attributes/'Digits

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Denorm
## Description

True if every value is expressible in canonical form with an an expo-nent of T’Machine_Emin.
Yields the value True if every value expressible in the form
± mantissa · T'Machine_Radix$^{T'Machine_Emin}$
where mantissa is a nonzero T'Machine_Mantissa-digit fraction in the number base T'Machine_Radix, the first digit of which is zero, is a machine number (see 3.5.7) of the type T; yields the value False otherwise.
The value of this attribute is of the predefined type Boolean.

## Example
# Ada Programming/Attributes/'Deref
## Description

The attribute typ'Deref(expr) where expr is of type System.Address yields the variable of type typ that is located at the given address. It is similar to (totyp (expr).all), where totyp is an unchecked conversion from address to a named access-to- type, except that it yields a variable, so it can be used on the left side of an assignment.

# Ada Programming/Attributes/'Descriptor Size
## Description

Nonstatic attribute Descriptor_Size returns the size in bits of the descriptor allocated for a type. The result is non-zero only for unconstrained array types and the returned value is of type universal integer. In GNAT, an array descriptor contains bounds information and is located immediately before the first element of the array.
The attribute takes into account any padding due to the alignment of the component type. In the example above, the descriptor contains two values of type Short_Short_Integer representing the low and high bound. But, since Positive has an alignment of 4, the size of the descriptor is 2 * Short_Short_Integer'Size rounded up to the next multiple of 32, which yields a size of 32 bits, i.e. including 16 bits of padding.

# Ada Programming/Attributes/'Digits
## Description

X'Digits is an Ada attribute where X is any floating point type or decimal fixed point type. This attribute represents the number of decimal digits in the mantissa of type X.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Elab Body
## Description

This attribute can only be applied to a program unit name. It returns the entity for the corresponding elaboration procedure for elaborating the body of the referenced unit. This is used in the main generated elaboration procedure by the binder and is not normally used in any other context. However, there may be specialized situations in which it is useful to be able to call this elaboration procedure from Ada code, e.g., if it is necessary to do selective re-elaboration to fix some error.

# Ada Programming/Attributes/'Elab Spec

This attribute can only be applied to a program unit name. It returns the entity for the corresponding elaboration procedure for elaborating the spec of the referenced unit. This is used in the main generated elaboration procedure by the binder and is not normally used in any other context. However, there may be specialized situations in which it is useful to be able to call this elaboration procedure from Ada code, e.g., if it is necessary to do selective re-elaboration to fix some error.

# Ada Programming/Attributes/'Elab Subp Body
## Description

This attribute can only be applied to a library level subprogram name and is only allowed in CodePeer mode. It returns the entity for the corresponding elaboration procedure for elaborating the body of the referenced subprogram unit. This is used in the main generated elaboration procedure by the binder in CodePeer mode only and is unrecognized otherwise.

# Ada Programming/Attributes/'Elaborated
## Description

The prefix of the 'Elaborated attribute must be a unit name. The value is a Boolean which indicates whether or not the given unit has been elaborated. This attribute is primarily intended for internal use by the generated code for dynamic elaboration checking, but it can also be used in user programs. The value will always be True once elaboration of all units has been completed. An exception is for units which need no elaboration, the value is always False for such units.

# Ada Programming/Attributes/'Emax
## Description

The Emax attribute is provided for compatibility with Ada 83. See the Ada 83 reference manual for an exact description of the semantics of this attribute.

# Ada Programming/Attributes/'Enabled
## Description

The Enabled attribute allows an application program to check at compile time to see if the designated check is currently enabled. The prefix is a simple identifier, referencing any predefined check name (other than All_Checks) or a check name introduced by pragma Check_Name. If no argument is given for the attribute, the check is for the general state of the check, if an argument is given, then it is an entity name, and the check indicates whether an Suppress or Unsuppress has been given naming the entity (if not, then the argument is ignored).
Note that instantiations inherit the check status at the point of the instantiation, so a useful idiom is to have a library package that introduces a check name with pragma Check_Name, and then contains generic packages or subprograms which use the Enabled attribute to see if the check is enabled. A user of this package can then issue a pragma Suppress or pragma Unsuppress before instantiating the package or subprogram, controlling whether the check will be present.

# Ada Programming/Attributes/'Enum Rep
## Description

This language feature has been introduced in Ada 2022. User_Enum_Type'Enum_Rep(Instance); where User_Enum_Type is an enumeration type and Instance is an instance of that type will return the underlying representation for that instance of the enumeration. The default representation of an enumeration is based on its position (starting at zero). However, Ada does provide language facilities for specifying the representation independently of the position. The Enum_Rep allows you to retrieve that representation. Generally in Ada, enumerations are their own type and the representation is not important. However, in the interests of cross language compatibility and for possible use in embedded programming the representation can be manipulated. While the core language allows you to change the representation, it doesn't provide a convenient attribute for retrieving it. This extended attribute addresses that need. Using it does require that you know the underlying type used to support the enumeration, since Enum_Rep returns that type. Typically, the standard type Integer is sufficient.
Note that this attribute is now standard in Ada 2022. In earlier Ada versions, it is available in GNAT as an implementation defined attribute, but the standard and portable way to get the internal representation was using an instantiation of Unchecked_Conversion.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Enum_Val

### Ada Reference Manual

* 13.4: Enumeration Representation Clauses
* Annex K: Language-Defined Attributes

### Ada 2022 Overview

* 7.13 Getting the representation of an enumeration value

### External links

GNAT Reference Manual > Implementation Defined Attributes > Enum_Rep

# Ada Programming/Attributes/'Enum Val

This language feature has been introduced in Ada 2022.

## Description

Return the enumeration literal represented by a given number.
For every enumeration subtype S, S'Enum_Val denotes a function with the following spec:
The function returns the enumeration value whose representation matches the argument, or raises Constraint_Error if no enumeration literal of the type has the matching value. This will be equal to the value of the Val attribute in the absence of an enumeration representation clause. This is a static attribute (i.e., the result is static if the argument is static).

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Enum_Rep

### Ada Reference Manual

* 13.4: Enumeration Representation Clauses
* Annex K: Language-Defined Attributes

### Ada 2022 Overview

* 7.13 Getting the representation of an enumeration value

### External links

GNAT Reference Manual > Implementation Defined Attributes > Enum_Val

# Ada Programming/Attributes/'Epsilon
## Description

The Epsilon attribute is provided for compatibility with Ada 83. See the Ada 83 reference manual for an exact description of the semantics of this attribute.

# Ada Programming/Attributes/'Exponent
## Description

Returns normalized exponent of the floating point argument.
For every subtype S of a floating point type T:
S'Exponent denotes a function with the following specification:
The function yields the normalized exponent of X.

## Example
# Ada Programming/Attributes/'Extended Aft
## Description

Returns the minimum number of characters required for the fractional part of the representation of the fixed point subtype T. All parameters are optional. They are:

### Base : Number_Base := 10

    the base in which the digits will be represented.

### Based : Boolean := FALSE

    if TRUE, compute the width of the based format (e.g.,10#99.0#).

## Example
# Ada Programming/Attributes/'Extended Base
## Description

For a type T returns the base type of T. This attribute is allowed only as the prefix of the name of another attribute. (This is the old Ada83 'BASE attribute.)

## Example
# Ada Programming/Attributes/'Extended Base
## Description

For a type T returns the base type of T. This attribute is allowed only as the prefix of the name of another attribute. (This is the old Ada83 'BASE attribute.)

## Example
# Ada Programming/Attributes/'Extended Digits
## Description

Returns the number of digits using Base in the mantissa of model numbers in the floating point subtype T. The optional parameter is:

### Base : Number_Base := 10

    the base that the subtype is defined in

## Example
# Ada Programming/Attributes/'Extended Fore
## Description

Returns the minimum number of characters required for the integer part of the representation of the fixed point subtype T. All parameters are optional. They are:

### Base : Number_Base := 10

    the base in which the digits will be represented.

### Based : Boolean := FALSE

    if TRUE, compute the width of the based format (e.g., 10#99.0#).

## Example
# Ada Programming/Attributes/'Extended Image
## Description

Returns the image of type STRING associated with a specified item as defined for the PUT procedure in TEXT_IO generic package appropriate for type T (e.g., TEXT_IO.INTEGER_IO(T) if T is an integer type). T may denote an integer, enumeration, floating point or fixed point type name. Named parameter notation may not be used. The parameters are:

### Item : T

    the item for which you want the image. Required.

### Width : Field := 0

    the minimum number of characters to be in the string that is returned.

### Base : Number_Base := 10

    the base in which the image is to be displayed.

### Based : Boolean := FALSE

    if TRUE, return the string in based format (e.g., 10#99#).

### Space_If_Positive : Boolean := FALSE

    if TRUE, a positive integer will be preceded by a blank in the string returned.

## Example
# Ada Programming/Attributes/'Extended Value
## Description

Returns the value of type T associated with Item as defined for the GET procedure in the TEXT_IO generic package appropriate for type T (e.g., TEXT_IO.INTEGER_IO(T) if T is an integer type). T may denote an integer, enumeration, floating point, or fixed point type.

### Item

    is the STRING for which you want the value.

## Example
# Ada Programming/Attributes/'Extended Wide Image
## Description

Returns the image of type WIDE_STRING associated with a specified item as defined for the PUT procedure in TEXT_IO generic package appropriate for type T (e.g., TEXT_IO.INTEGER_IO(T) if T is an integer type). T may denote an integer, enumeration, floating point or fixed point type name. Named parameter notation may not be used. The parameters are:

### Item : T

    the item for which you want the image. Required.

### Width : Field := 0

    the minimum number of characters to be in the string that is returned.

### Base : Number_Base := 10

    the base in which the image is to be displayed.

### Based : Boolean := FALSE

    if TRUE, return the string in based format (e.g., 10#99#).

### Space_If_Positive : Boolean := FALSE

    if TRUE, a positive integer will be preceded by a blank in the string returned.

## Example
# Ada Programming/Attributes/'Extended Wide Value
## Description

Returns the value of type T associated with Item as defined for the GET procedure in the TEXT_IO generic package appropriate for type T (e.g., TEXT_IO.INTEGER_IO(T) if T is an integer type). T may denote an integer, enumeration, floating point, or fixed point type.

### Item

    is the WIDE_STRING for which you want the value.

## Example
# Ada Programming/Attributes/'Extended Wide Width
## Description

Returns the width for (sub)type T. T may be integer or enumeration type. All the parameters are optional. They are:

### Base : Number_Base := 10

    the base for which the width will be calculated.

### Based : Boolean := FALSE

    if TRUE, compute the width of the based format (e.g., 10#99#).

### Space_If_Positive : BOOLEAN := FALSE

    if TRUE, compute the width assuming that a positive integer will be preceded by a blank.

## Example
# Ada Programming/Attributes/'Extended Width
## Description

Returns the width for (sub)type T. T may be integer or enumeration type. All the parameters are optional. They are:

### Base : Number_Base := 10

    the base for which the width will be calculated.

### Based : Boolean := FALSE

    if TRUE, compute the width of the based format (e.g., 10#99#).

### Space_If_Positive : BOOLEAN := FALSE

    if TRUE, compute the width assuming that a positive integer will be preceded by a blank.

## Example
# Ada Programming/Attributes/'External Tag
## Description

An external string representation of the tagged type.
For every subtype S of a tagged type T (specific or class-wide):
S'External_Tag denotes an external string representation for S'Tag; it is of the predefined type String. External_Tag may be specified for a specific tagged type via an attribute_definition_clause; the expression of such a clause shall be static. The default external tag representation is implementation defined.

## Example
# Ada Programming/Attributes/'Fast Math
## Description

Standard'Fast_Math (Standard is the only allowed prefix) yields a static Boolean value that is True if pragma Fast_Math is active, and False otherwise.

# Ada Programming/Attributes/'Finalization Size
## Description

The prefix of attribute Finalization_Size must be an object or a non-class-wide type. This attribute returns the size of any hidden data reserved by the compiler to handle finalization-related actions. The type of the attribute is universal_integer.
Finalization_Size yields a value of zero for a type with no controlled parts, an object whose type has no controlled parts, or an object of a class-wide type whose tag denotes a type with no controlled parts.
Note that only heap-allocated objects contain finalization data.

# Ada Programming/Attributes/'First
## Description

X'First, where X is any scalar subtype (for example integer, enumerated, real), is an attribute that represents the first value (lower bound) in the range of X.
A'First, where A is an array, denotes the first index value. For more-dimensional arrays, A'First(N) denotes the first index value of the Nth dimension (N must be static).

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Last
* Range

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Fixed Value
## Description

For every fixed-point type S, S'Fixed_Value denotes a function with the following specification:
The value returned is the fixed-point value V such that:
The effect is thus similar to first converting the argument to the integer type used to represent S, and then doing an unchecked conversion to the fixed-point type. The difference is that there are full range checks, to ensure that the result is in range. This attribute is primarily intended for use in implementation of the input-output functions for fixed-point values.

# Ada Programming/Attributes/'Floor
## Description

X'Floor(Y) is an Ada attribute where X is any floating-point type and Y is any instance of that type. This attribute represents the largest integer value that is less than or equal to Y.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Ceiling
* Ada Programming/Attributes/'Rounding

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Fore
## Description

Minimum number of characters needed before the decimal point.
S'Fore yields the minimum number of characters needed before the decimal point for the decimal representation of any value of the subtype S, assuming that the representation does not include an exponent, but includes a one-character prefix that is either a minus sign or a space. (
This minimum number does not include superfluous zeros or underlines, and is at least 2.)
The value of this attribute is of the type universal_integer.

## Example
# Ada Programming/Attributes/'Fraction
## Description

X'Fraction(Y) is an Ada attribute where X is any floating-point type and Y is any instance of that type.
X'Fraction(Y) returns the floating point number Y with the exponent replaced with 0. This is the same as X'Compose(Y, 0).

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Compose

### Ada Reference Manual

* 5.3 Attributes of Floating Point Types (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'From Any
## Description

This internal attribute is used for the generation of remote subprogram stubs in the context of the Distributed Systems Annex.

# Ada Programming/Attributes/'Has Access Values
## Description

The prefix of the Has_Access_Values attribute is a type. The result is a Boolean value which is True if the is an access type, or is a composite type with a component (at any nesting depth) that is an access type, and is False otherwise. The intended use of this attribute is in conjunction with generic definitions. If the attribute is applied to a generic private type, it indicates whether or not the corresponding actual type has access values.

# Ada Programming/Attributes/'Has Discriminants
## Description

The prefix of the Has_Discriminants attribute is a type. The result is a Boolean value which is True if the type has discriminants, and False otherwise. The intended use of this attribute is in conjunction with generic definitions. If the attribute is applied to a generic private type, it indicates whether or not the corresponding actual type has discriminants.

# Ada Programming/Attributes/'Has Same Storage
## Description

Returns True if the representation of X2 occupies exactly the same bits as the representation of X and the objects occupy at least one bit.
For a prefix X that denotes an object:
X'Has_Same_Storage denotes a function with the following specification:
The actual parameter shall be a name that denotes an object. The object denoted by the actual parameter can be of any type. This function evaluates the names of the objects involved. It returns True if the representation of the object denoted by the actual parameter occupies exactly the same bits as the representation of the object denoted by X and the objects occupy at least one bit; otherwise, it returns False.

## Example
# Ada Programming/Attributes/'Has Tagged Values
## Description

The prefix of the Has_Tagged_Values attribute is a type. The result is a Boolean value which is True if the type is a composite type (array or record) that is either a tagged type or has a subcomponent that is tagged, and is False otherwise. The intended use of this attribute is in conjunction with generic definitions. If the attribute is applied to a generic private type, it indicates whether or not the corresponding actual type has access values.

# Ada Programming/Attributes/'Identity
## Description

X'Identity is an Ada attribute where X is any task. This attribute returns a unique identifying string (of type "Task_ID"). This string is used in some Ada tasking libraries for task identification. It may also be used directly by the user for output purposes, to determine if two tasks are the same task, etc.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Image
## Description

X'Image(Y) is an Ada attribute where X is any discrete type and Y is an instance of that type. This attribute returns a string representation of the value passed as input.
This attribute is a useful way to automatically convert from a type value to a string suitable for output.
In Ada 2022 a simplified version was added:
Y’Image return String
Image of the value of Y as a String.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Value

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Img
## Description

The Img attribute differs from Image in that, while both can be applied directly to an object, Img cannot be applied to types.
Example usage of the attribute:
which has the same meaning as the more verbose:
where T is the (sub)type of the object X.
Note that technically, in analogy to Image, X'Img returns a parameterless function that returns the appropriate string when called. This means that X'Img can be renamed as a function-returning-string, or used in an instantiation as a function parameter.

# Ada Programming/Attributes/'Index
## Description

Within a precondition or postcondition expression for entry family E, denotes the value of the entry index for the call of E.

## Example
# Ada Programming/Attributes/'Initialized
## Description

For the syntax and semantics of this attribute, see the SPARK 2014 Reference Manual, section 6.10.

# Ada Programming/Attributes/'Input
## Description

Reads and returns one value from the Stream argument.
For every subtype S of a specific type T:
S'Input denotes a function with the following specification:
S'Input reads and returns one value from Stream, using any bounds or discriminants written by a corresponding S'Output to determine how much to read.

## Example
# Ada Programming/Attributes/'Integer Value
## Description

For every integer type S, S'Integer_Value denotes a function with the following spec:
The value returned is the integer value V, such that:
where T is the type of Arg. The effect is thus similar to first doing an unchecked conversion from the fixed-point type to its corresponding implementation type, and then converting the result to the target integer type. The difference is that there are full range checks, to ensure that the result is in range. This attribute is primarily intended for use in implementation of the standard input-output functions for fixed-point values.

# Ada Programming/Attributes/'Invalid Value
## Description

For every scalar type S, S’Invalid_Value returns an undefined value of the type. If possible this value is an invalid representation for the type. The value returned is identical to the value used to initialize an otherwise uninitialized value of the type if pragma Initialize_Scalars is used, including the ability to modify the value with the binder -Sxx flag and relevant environment variables at run time.

# Ada Programming/Attributes/'Large

The Large attribute is provided for compatibility with Ada 83. See the Ada 83 reference manual for an exact description of the semantics of this attribute.

# Ada Programming/Attributes/'Last
## Description

X'Last, where X is any scalar subtype (for example integer, enumerated, real), is an attribute that represents the last value (upper bound) in the range of X.
A'Last, where A is an array, denotes the last index value. For more-dimensional arrays, A'Last(N) denotes the last index value of the Nth dimension (N must be static).

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'First
* Ada Programming/Attributes/'Range

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Leading Part
## Description

The leading part of floating point value with number of radix digits given by second argument.

## Example
# Ada Programming/Attributes/'Length
## Description

'Length is an array type attribute. It may be used with or without an input parameter.
Without an input parameter, 'Length is an integer that represents the length of the first dimension of the array type.
With an input parameter, 'Length(N) is an integer that represents the length of the Nth dimension of the array type. N must be a positive number within the dimensions of the array.

## Example

If you declare:
then

## See also
### Wikibook

* Ada Programming

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Library Level
## Description

P'Library_Level, where P is an entity name, returns a Boolean value which is True if the entity is declared at the library level, and False otherwise. Note that within a generic instantiation, the name of the generic unit denotes the instance, which means that this attribute can be used to test if a generic is instantiated at the library level, as shown in this example:

# Ada Programming/Attributes/'Loop Entry
## Description

The Loop_Entry attribute is used to refer to the value that an expression had upon entry to a given loop in much the same way that the Old attribute in a subprogram postcondition can be used to refer to the value an expression had upon entry to the subprogram. The relevant loop is either identified by the given loop name, or it is the innermost enclosing loop when no loop name is given.
A Loop_Entry attribute can only occur within an Assert, Assert_And_Cut, Assume, Loop_Variant or Loop_Invariant pragma. In addition, such a pragma must be one of the items in the sequence of statements of a loop body, or nested inside block statements that appear in the sequence of statements of a loop body. A common use of Loop_Entry is to compare the current value of objects with their initial value at loop entry, in a Loop_Invariant pragma.
The effect of using X'Loop_Entry is the same as declaring a constant initialized with the initial value of X at loop entry. This copy is not performed if the loop is not entered, or if the corresponding pragmas are ignored or disabled.

# Ada Programming/Attributes/'Machine
## Description

Machine representation of floating point argument.
If X is a machine number of the type T, the function yields X; otherwise, it yields the value obtained by rounding or truncating X to either one of the adjacent machine numbers of the type T.
Constraint_Error is raised if rounding or truncating X to the precision of the machine numbers results in a value outside the base range of S.
A zero result has the sign of X when S'Signed_Zeros is True.

## Example
# Ada Programming/Attributes/'Machine Emax
## Description

X'Machine_Emax is an Ada attribute where X is any floating point type.
Floating point types are represented as:
    $sign\times mantissa\times radix^{exponent}$
where
    sign is 1 or -1
    mantissa is a fraction in base radix
    radix is the hardware radix (usually 2)
    exponent is an integer
'Machine_Emax returns the largest exponent.

## Example

The output with GNAT 4.6 on the x86-64 architecture is:

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Machine_Emin
* Ada Programming/Attributes/'Machine_Mantissa
* Ada Programming/Attributes/'Machine_Radix

### Ada Reference Manual

* 5.3 Attributes of Floating Point Types (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Machine Emin
## Description

X'Machine_Emin is an Ada attribute where X is any floating point type.
Floating point types are represented as:
    $sign\times mantissa\times radix^{exponent}$
where
    sign is 1 or -1
    mantissa is a fraction in base radix
    radix is the hardware radix (usually 2)
    exponent is an integer
'Machine_Emin returns the smallest exponent.

## Example

The output with GNAT 4.6 on the x86-64 architecture is:

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Machine_Emax
* Ada Programming/Attributes/'Machine_Mantissa
* Ada Programming/Attributes/'Machine_Radix

### Ada Reference Manual

* 5.3 Attributes of Floating Point Types (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Machine Mantissa
## Description

X'Machine_Mantissa is an Ada attribute where X is any floating point type.
Floating point types are represented as:
    $sign\times mantissa\times radix^{exponent}$
where
    sign is 1 or -1
    mantissa is a fraction in base radix
    radix is the hardware radix (usually 2)
    exponent is an integer
'Machine_Mantissa returns the maximum number of digits in the mantissa.

## Example

The output with GNAT 4.6 on the x86-64 architecture is:

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Machine_Emax
* Ada Programming/Attributes/'Machine_Emin
* Ada Programming/Attributes/'Machine_Radix

### Ada Reference Manual

* 5.3 Attributes of Floating Point Types (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Machine Overflows
## Description

True if numeric overflow detected for fixed or floating point.
Yields the value True if overflow and divide-by-zero are detected and reported by raising Constraint_Error for every predefined operation that yields a result of the type T; yields the value False otherwise.
The value of this attribute is of the predefined type Boolean.

## Example
# Ada Programming/Attributes/'Machine Radix
## Description

X'Machine_Radix is an Ada attribute where X is any floating or fixed point type. It returns the radix of the hardware representation of type X. On most machines this will be 2.
Machine_Radix is also an Ada aspect that may be set for decimal fixed point types via an attribute definition clause. The value is constrained to either 2 or 10.

## Example

The output with GNAT 4.6 on the x86-64 architecture is:

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Machine_Emax
* Ada Programming/Attributes/'Machine_Emin
* Ada Programming/Attributes/'Machine_Mantissa

### Ada Reference Manual

* A.5.3: Attributes of Floating Point Types
* A.5.4: Attributes of Fixed Point Types
* Annex K: Language-Defined Aspects and Attributes

# Ada Programming/Attributes/'Machine Rounding
## Description

Yields the integral value nearest to X.
The function yields the integral value nearest to X.
If X lies exactly halfway between two integers, one of those integers is returned, but which of them is returned is unspecified.
A zero result has the sign of X when S'Signed_Zeros is True.
This function provides access to the rounding behavior which is most efficient on the target processor.

## Example
# Ada Programming/Attributes/'Machine Rounds
## Description

True if rounding is performed on inexact results of the fixed or floating point.
Yields the value True if rounding is performed on inexact results of every predefined operation that yields a result of the type T; yields the value False otherwise.
The value of this attribute is of the predefined type Boolean.

## Example
# Ada Programming/Attributes/'Machine Size
## Description

This attribute is identical to the Object_Size attribute. It is provided for compatibility with the DEC Ada 83 attribute of this name.

# Ada Programming/Attributes/'Mantissa
## Description

The Mantissa attribute is provided for compatibility with Ada 83. See the Ada 83 reference manual for an exact description of the semantics of this attribute.

# Ada Programming/Attributes/'Max
## Description

'Max(X, Y) is a scalar type attribute. It returns the greater of the two parameters.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Min

### Ada Reference Manual

* 3.5 Scalar Types (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Max Alignment For Allocation
## Description

Maximum value for Alignment that can be requested by the implementation via Allocate for an access type whose designated subtype is S.
Denotes the maximum value for Alignment that can be requested by the implementation via Allocate for an access type whose designated subtype is S.
The value of this attribute is of type universal_integer.

## Example
# Ada Programming/Attributes/'Max Integer Size
## Description

Standard'Max_Integer_Size (Standard is the only allowed prefix) provides the size of the largest supported integer type for the target. The result is a static constant.

# Ada Programming/Attributes/'Max Size In Storage Elements
## Description

Maximum value for Size_In_Storage_Elements that will be requested via Allocate.
Denotes the maximum value for Size_In_Storage_Elements that can be requested by the implementation via Allocate for an access type whose designated subtype is S. The value of this attribute is of type universal_integer.

## Example
# Ada Programming/Attributes/'Maximum Alignment
## Description

Standard'Maximum_Alignment (Standard is the only allowed prefix) provides the maximum useful alignment value for the target. This is a static value that can be used to specify the alignment for an object, guaranteeing that it is properly aligned in all cases.

# Ada Programming/Attributes/'Mechanism Code
## Description

func'Mechanism_Code yields an integer code for the mechanism used for the result of function func, and subprog'Mechanism_Code (n) yields the mechanism used for formal parameter number n (a static integer value, with 1 meaning the first parameter) of subprogram subprog. The code returned is:

### 1

    by copy (value)

### 2

    by reference

# Ada Programming/Attributes/'Min
## Description

'Min(X, Y) is a scalar type attribute. It returns the lesser of the two parameters.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Max

### Ada Reference Manual

* 3.5 Scalar Types (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Mod
## Description

Will correctly convert any integer type to a given modular type (S), using wraparound semantics.
This function returns Arg mod S'Modulus, as a value of the type of S.

## Example
# Ada Programming/Attributes/'Model
## Description

Model number of floating point type.
If the Numerics Annex is not supported, the meaning of this attribute is implementation defined.

## Example
# Ada Programming/Attributes/'Model Emin
## Description

Model number version of S”Machine_Emin.
Yields the smallest (most negative) value of exponent such that every value expressible in the canonical form (for the type T), having a mantissa of T'Machine_Mantissa digits, is a machine number (see 3.5.7) of the type T.
This attribute yields a value of the type universal_integer.

## Example
# Ada Programming/Attributes/'Model Epsilon
## Description

Absolute difference between the model number 1.0 and the next model number above for subtype.
Yields the value T'Machine_Radix$^{1–T'Model_Mantissa}$. The value of this attribute is of the type universal_real.

## Example
# Ada Programming/Attributes/'Model Mantissa
## Description

Model number version of S’Machine_Mantissa.
Yields the largest value of p such that every value expressible in the canonical form (for the type T), having a p-digit mantissa and an exponent between T'Machine_Emin and T'Machine_Emax, is a machine number of the type T. This attribute yields a value of the type universal_integer.

## Example
# Ada Programming/Attributes/'Model Small
## Description

Smallest positive model number of subtype.
Yields the value T'Machine_Radix$^{T'Model_Emin–1}$. The value of this attribute is of the type universal_real.

## Example
# Ada Programming/Attributes/'Modulus
## Description

X'Modulus is an Ada attribute where X is any modular type. This returns the modulus of X.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes

### Ada Reference Manual

* 3.5-4 Integer Types (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Null Parameter
## Description

A reference T'Null_Parameter denotes an imaginary object of type or subtype T allocated at machine address zero. The attribute is allowed only as the default expression of a formal parameter, or as an actual expression of a subprogram call. In either case, the subprogram must be imported.
The identity of the object is represented by the address zero in the argument list, independent of the passing mechanism (explicit or default).
This capability is needed to specify that a zero address should be passed for a record or other composite object passed by reference. There is no way of indicating this without the Null_Parameter attribute.

# Ada Programming/Attributes/'Object Size
## Description

The size of an object is not necessarily the same as the size of the type of an object. This is because by default object sizes are increased to be a multiple of the alignment of the object. For example, Natural'Size is 31, but by default objects of type Natural will have a size of 32 bits. Similarly, a record containing an integer and a character:
will have a size of 40 (that is Rec'Size will be 40). The alignment will be 4, because of the integer field, and so the default size of record objects for this type will be 64 (8 bytes).
If the alignment of the above record is specified to be 1, then the object size will be 40 (5 bytes). This is true by default, and also an object size of 40 can be explicitly specified in this case.
A consequence of this capability is that different object sizes can be given to subtypes that would otherwise be considered in Ada to be statically matching. But it makes no sense to consider such subtypes as statically matching. Consequently, GNAT adds a rule to the static matching rules that requires object sizes to match. Consider this example:
In the absence of lines 5 and 6, types R1 and R2 statically match and hence the conversion on line 12 is legal. But since lines 5 and 6 cause the object sizes to differ, GNAT considers that types R1 and R2 are not statically matching, and line 12 generates the diagnostic shown above.
Similar additional checks are performed in other contexts requiring statically matching subtypes.

# Ada Programming/Attributes/'Old
## Description

The value of X on entry, has same type as X.
Each X'Old in a postcondition expression that is enabled, other than those that occur in subexpressions that are determined to be unevaluated, denotes a constant that is implicitly declared at the beginning of the subprogram body, entry body, or accept statement.

## Example
# Ada Programming/Attributes/'Output
## Description

Writes the value of X to Stream, including any bounds or discriminants.

## Example
# Ada Programming/Attributes/'Overlaps Storage
## Description

Returns True if the representation of X2 shares at least one bit with the representation of the object denoted by X.
The actual parameter shall be a name that denotes an object. The object denoted by the actual parameter can be of any type. This function evaluates the names of the objects involved and returns True if the representation of the object denoted by the actual parameter shares at least one bit with the representation of the object denoted by X; otherwise, it returns False.

## Example
# Ada Programming/Attributes/'Parallel Reduce
## Description

Reduction expression that yields a result equivalent to replacing the attribute identifier with Reduce and the prefix of the attribute with the value_sequence.
X'Parallel_Reduce is a reduction expression that yields a result equivalent to replacing the attribute identifier with Reduce and the prefix of the attribute with the value_sequence:
[parallel for Item of X => Item]

## Example
# Ada Programming/Attributes/'Partition ID
## Description

Identifies the partition in which D was elaborated.
Denotes a value of the type universal_integer that identifies the partition in which D was elaborated. If D denotes the declaration of a remote call interface library unit the given partition is the one where the body of D was elaborated.

## Example
# Ada Programming/Attributes/'Passed By Reference
## Description

typ'Passed_By_Reference for any subtype returns a value of type Boolean value that is True if the type is normally passed by reference and False if the type is normally passed by copy in calls. For scalar types, the result is always False and is static. For non-scalar types, the result is nonstatic.

# Ada Programming/Attributes/'Pool Address
## Description

X'Pool_Address for any object X returns the address of X within its storage pool. This is the same as X'Address, except that for an unconstrained array whose bounds are allocated just before the first component, X'Pool_Address returns the address of those bounds, whereas X'Address returns the address of the first component.
Here, we are interpreting ‘storage pool’ broadly to mean wherever the object is allocated, which could be a user-defined storage pool, the global heap, on the stack, or in a static memory area. For an object created by new, Ptr.all'Pool_Address is what is passed to Allocate and returned from Deallocate.

# Ada Programming/Attributes/'Pos
## Description

The 'Pos attribute is defined for all discrete types. It is a function returning the argument's position number as a universal_integer; the prefix S must be a subtype name. (Universal integers are implicitly converted to any specific integer type as required by the context.)
For enumeration types, position numbers start at 0; if the argument does not denote a valid value (perhaps because of an uninitialized variable), the exception Program_Error is raised. For integer types, the attribute returns the value converted to universal_integer. Note that it is not necessary for the actual argument to belong to the subtype S.
Note that representation clauses do not affect position numbering. Whatever underlying value the enumerated value has, the position number will remain the same.

## Example

Another example without representation clause:

## See also

The inverse of the 'Pos attribute is 'Val.
The underlying representation can be obtained using an Unchecked_Conversion, or with the implementation-defined attribute 'Enum_Rep (GNAT).
For a detailed explanation of universal_integer, see Type System: Elaborated Discussion of Types for Signed Integer Types.

### Wikibook

* Ada Programming
* Ada Programming/Attributes/'Val
* Ada Programming/Attributes/'Valid

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Position
## Description

'Position is a record type component attribute. It represents the address offset of the component from the beginning of the record. The value returned is represented in storage units, which is machine-specific. The attribute is closely related to the attributes 'First_Bit and 'Last_Bit. Together they specify the Layout aspect of records.
See Representation Clauses.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Bit_Order

### Ada Reference Manual

* 13.3: Operational and Representation Attributes
* Annex K: Language-Defined Attributes

# Ada Programming/Attributes/'Pred
## Description

X'Pred(Y) is an Ada attribute where X is any discrete type and Y is a value of that type. This attribute represents the discrete value that has a position number of one less than the input parameter.
The returned discrete value type is the base type of discrete type. If the input parameter is the First value of the discrete type, then a CONSTRAINT_ERROR exception will be raised.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes/'Succ

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Preelaborable Initialization
## Description

Returns whether the type of S has preelaborable initialization.

## Description
# Ada Programming/Attributes/'Preelaborate Initialization
## Description

Returns whether the type of S has preelaborable initialization.
For a nonformal composite subtype S declared within the visible part of a package or a generic package, or a generic formal private subtype or formal derived subtype:
This attribute is of Boolean type, and its value reflects whether the type of S has preelaborable initialization.

## Example
# Ada Programming/Attributes/'Priority
## Description

Returns the priority of P.
Denotes a non-aliased component of the protected object P. This component is of type System.Any_Priority and its value is the priority of P. P'Priority denotes a variable if and only if P denotes a variable. A reference to this attribute shall appear only within the body of P.

## Example
# Ada Programming/Attributes/'Put Image
## Description

Writes an image of the value of X.

## Example
# Ada Programming/Attributes/'Range
## Description

The meaning of the attribute depends on the meaning of the prefix X.
If X is a scalar subtype, X'Range represents the range of valid values for that subtype, i.e. it is the same as the subtype itself.
If X is a constrained array subtype or an array object, X'Range denotes the index range of X.
In any case, X'Range is equivalent to X'First .. X'Last, but X is only evaluated once.
If X is multidimensional, the attribute needs a static parameter N to identify the N-th index; 'Range (1) is the same as 'Range.
X'Range (N) is equivalent to X'First(N) .. X'Last(N), but X is only evaluated once.

## See also
### Wikibook

* Ada Programming

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Range Length
## Description

typ'Range_Length for any discrete type yields the number of values represented by the subtype (zero for a null range). The result is static for static subtypes. Range_Length applied to the index subtype of a one dimensional array always gives the same result as Length applied to the array itself.

# Ada Programming/Attributes/'Read
## Description

Reads the value of X from Stream.

## Example
# Ada Programming/Attributes/'Reduce
## Description

This attribute represents a reduction expression, and is in the form of a reduction_attribute_reference.

## Example
# Ada Programming/Attributes/'Ref
## Description

’REF denotes the effective address of the first of the storage units allocated to the object. ’REF is not supported for a package, task unit or entry. The two forms for this attribute are X’REF and SYSTEM.ADDRESS’REF(N). Only use X’REF in machine code procedures. Use SYSTEM.ADDRESS’REF(N) anywhere to convert an integer expression to an address.

#### X’REF

The attribute generates a reference to the entity to which it is applied. In X’REF, X must be either a constant, variable, procedure, function, or label. The attribute returns a value of the type MACHINE_CODE.OPERAND. Only use it to designate an operand in a code-statement. Precede the instruction generated by the code-statement in which the attribute occurs by additional instructions needed to facilitate the reference, such as loading a base register. If the declarative section of the procedure contains pragma IMPLICIT_CODE (OFF), a warning generates if additional code is required.

#### SYSTEM.ADDRESS’REF(N)

The effect of this attribute is similar to the effect of an unchecked conversion from integer to address. However, use SYSTEM.ADDRESS’REF(N) instead in the following listed circumstances. In these circumstances, N must be static. In SYSTEM.ADDRESS’REF(N), SYSTEM.ADDRESS must be type SYSTEM.ADDRESS. N must be an expression of type UNIVERSAL_INTEGER. The attribute returns a value of type SYSTEM.ADDRESS, which represents the address designated by N.
* With any of the runtime configuration packages: Use of unchecked conversion in an address clause requires the generation of elaboration code, but the configuration packages are not elaborated.
* In any instance where N is greater than INTEGER’LAST: Such values are required in address clauses that reference the upper portion of memory. To use unchecked conversion in these instances requires the expression be given as a negative integer.
* To place an object at an address, use ’REF.

## Example

In the following example, the integer_value converts to an address for use in the address representation clause. The form avoids UNCHECKED_CONVERSION and is useful for 32-bit unsigned addresses.

# Ada Programming/Attributes/'Relative Deadline
## Description

Relative deadline of P.
Denotes a non-aliased component of the protected object P. This component is of type Ada.Real_Time.Time_Span and its value is the relative deadline of P. P'Relative_Deadline denotes a variable if and only if P denotes a variable. A reference to this attribute shall appear only within the body of P.

## Example
# Ada Programming/Attributes/'Remainder
## Description

X'Remainder(Y,Z) is an Ada attribute where X is any floating-point type and Y,Z are any instances of that type. This attribute represents the fractional part of this result. Z should never be zero.
The sign of Y may or may not be the same as the sign of the result.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Rounding
* Ada Programming/Attributes/'Truncation
* Ada Programming/Attributes/'Unbiased_Rounding

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Restriction Set
## Description

This attribute allows compile time testing of restrictions that are currently in effect. It is primarily intended for specializing code in the run-time based on restrictions that are active (e.g. don’t need to save fpt registers if restriction No_Floating_Point is known to be in effect), but can be used anywhere.
There are two forms:
In the case of the first form, the only restriction names allowed are parameterless restrictions that are checked for consistency at bind time. For a complete list see the subtype System.Rident.Partition_Boolean_Restrictions.
The result returned is True if the restriction is known to be in effect, and False if the restriction is known not to be in effect. An important guarantee is that the value of a Restriction_Set attribute is known to be consistent throughout all the code of a partition.
This is trivially achieved if the entire partition is compiled with a consistent set of restriction pragmas. However, the compilation model does not require this. It is possible to compile one set of units with one set of pragmas, and another set of units with another set of pragmas. It is even possible to compile a spec with one set of pragmas, and then WITH the same spec with a different set of pragmas. Inconsistencies in the actual use of the restriction are checked at bind time.
In order to achieve the guarantee of consistency for the Restriction_Set pragma, we consider that a use of the pragma that yields False is equivalent to a violation of the restriction.
So for example if you write
And the result is False, so that the else branch is executed, you can assume that this restriction is not set for any unit in the partition. This is checked by considering this use of the restriction pragma to be a violation of the restriction No_Floating_Point. This means that no other unit can attempt to set this restriction (if some unit does attempt to set it, the binder will refuse to bind the partition).
Technical note: The restriction name and the unit name are intepreted entirely syntactically, as in the corresponding Restrictions pragma, they are not analyzed semantically, so they do not have a type.

# Ada Programming/Attributes/'Result
## Description

Within a postcondition expression for F, denotes the return object of the function call for which the postcondition expression is evaluated.
Within a postcondition expression for F, denotes the return object of the function call for which the postcondition expression is evaluated. The type of this attribute is that of the result subtype of the function or access-to-function type except within a Post'Class postcondition expression for a function with a controlling result or with a controlling access result; in those cases the type of the attribute is described above as part of the Name Resolution Rules for Post'Class.

## Example
# Ada Programming/Attributes/'Round
## Description

Fixed-point value obtained by rounding X (away from 0, if X is midway between two values).
The function returns the value obtained by rounding X (away from 0, if X is midway between two values of the type of S).

## Example
# Ada Programming/Attributes/'Rounding
## Description

X'Rounding(Y) is an Ada attribute where X is any floating-point type and Y is any instance of that type. This attribute represents the closest integer value to Y. If Y is exactly between two integer values (e.g. 1.5), then the result is the number farthest away from zero (e.g. 1.5 => 2.0, -1.5 => -2.0).

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Ceiling
* Ada Programming/Attributes/'Floor
* Ada Programming/Attributes/'Unbiased_Rounding

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Safe Emax
## Description

The Safe_Emax attribute is provided for compatibility with Ada 83. See the Ada 83 reference manual for an exact description of the semantics of this attribute.

# Ada Programming/Attributes/'Safe First
## Description

Returns lower bound of the safe range.
Yields the lower bound of the safe range (see 3.5.7) of the type T. If the Numerics Annex is not supported, the value of this attribute is implementation defined.
The value of this attribute is of the type universal_real.

## Example
# Ada Programming/Attributes/'Safe Large
## Description

The Safe_Large attribute is provided for compatibility with Ada 83. See the Ada 83 reference manual for an exact description of the semantics of this attribute.

# Ada Programming/Attributes/'Safe Last
## Description

Returns upper bound of the safe range.
Yields the upper bound of the safe range (see 3.5.7) of the type T. If the Numerics Annex is not supported, the value of this attribute is implementation defined. The value of this attribute is of the type universal_real.

## Example
# Ada Programming/Attributes/'Safe Small
## Description

The Safe_Small attribute is provided for compatibility with Ada 83. See the Ada 83 reference manual for an exact description of the semantics of this attribute.

# Ada Programming/Attributes/'Scalar Storage Order
## Description

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:
Other properties are as for the standard representation attribute Bit_Order 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 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 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:
* the underlying storage elements are those at positions (position + first_bit / storage_element_size) .. (position + (last_bit + storage_element_size - 1) / storage_element_size)
* 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 position + first_bit / storage_element_size and covering storage elements at least up to position + (last_bit + storage_element_size - 1) / storage_element_size
* 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 Default_Scalar_Storage_Order.
If a component of T is itself of a record or array type, the specfied Scalar_Storage_Order 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 Ada.Unchecked_Conversion.
In particular, overlays are not supported and a warning is given for them:
warning: overlay changes scalar storage order [enabled by default]
In most cases, such representation changes ought to be replaced by an instantiation of a function or procedure provided by GNAT.Byte_Swapping.
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.

# Ada Programming/Attributes/'Scale
## Description

Position of the fixed-point relative to the rightmost significant digits of values of subtype S.
S'Scale denotes the scale of the subtype S, defined as the value N such that S'Delta = 10.0**(–N). The scale indicates the position of the point relative to the rightmost significant digits of values of subtype S. The value of this attribute is of the type universal_integer.

## Example
# Ada Programming/Attributes/'Scaling
## Description

Scaling by a power of the hardware radix.
Let v be the value X · T'Machine_Radix$^{Adjustment}$. If v is a machine number of the type T, or if |v| ≥ T'Model_Small, the function yields v; otherwise, it yields either one of the machine numbers of the type T adjacent to v. Constraint_Error is optionally raised if v is outside the base range of S. A zero result has the sign of X when S'Signed_Zeros is True.

## Example
# Ada Programming/Attributes/'Signed Zeros
## Description

True if positive and negative signed zeros are representable.
Yields the value True if the hardware representation for the type T has the capability of representing both positively and negatively signed zeros, these being generated and used by the predefined operations of the type T as specified in IEC 559:1989; yields the value False otherwise. The value of this attribute is of the predefined type Boolean.

## Example
# Ada Programming/Attributes/'Simple Storage Pool
## Description

For every nonformal, nonderived access-to-object type Acc, the representation attribute Simple_Storage_Pool may be specified via an attribute_definition_clause (or by specifying the equivalent aspect):
The name given in an attribute_definition_clause for the Simple_Storage_Pool attribute shall denote a variable of a ‘simple storage pool type’ (see pragma ).
The use of this attribute is only allowed for a prefix denoting a type for which it has been specified. The type of the attribute is the type of the variable specified as the simple storage pool of the access type, and the attribute denotes that variable.
It is illegal to specify both Storage_Pool and Simple_Storage_Pool for the same access type.
If the Simple_Storage_Pool attribute has been specified for an access type, then applying the Storage_Pool attribute to the type is flagged with a warning and its evaluation raises the exception Program_Error.
If the Simple_Storage_Pool attribute has been specified for an access type S, then the evaluation of the attribute S'Storage_Size returns the result of calling Storage_Size (S'Simple_Storage_Pool), which is intended to indicate the number of storage elements reserved for the simple storage pool. If the Storage_Size function has not been defined for the simple storage pool type, then this attribute returns zero.
If an access type S has a specified simple storage pool of type SSP, then the evaluation of an allocator for that access type calls the primitive Allocate procedure for type SSP, passing S'Simple_Storage_Pool as the pool parameter. The detailed semantics of such allocators is the same as those defined for allocators in section 13.11 of the , with the term simple storage pool substituted for storage pool.
If an access type S has a specified simple storage pool of type SSP, then a call to an instance of the Ada.Unchecked_Deallocation for that access type invokes the primitive Deallocate procedure for type SSP, passing S'Simple_Storage_Pool as the pool parameter. The detailed semantics of such unchecked deallocations is the same as defined in section 13.11.2 of the Ada Reference Manual, except that the term simple storage pool is substituted for storage pool.

# Ada Programming/Attributes/'Size
## Description

R'Size is a representation attribute used to get the number of bits of an object or type:
* When applied to an object, 'Size yields the actual number of bits allocated to store the object.
* When applied to a subtype, 'Size yields the smallest n such that all values fit in the range 0 .. 2$^n$-1 for only positive values, else -2$^{n-1}$ .. 2$^{n-1}$-1.
The 'Size attribute may also be used in an attribute definition clause to set the size for a first subtype. In special cases, it is even possible to force a biased representation by using a smaller value than the n above.

## Examples

This subtype allows a biased representation with only three bits because it comprises only eight values:
Without the size clause, T'Size would return 10 because 2$^{10}$-1 = 1023.
The output with GNAT 10.2.0 will be:
Try it yourself and see how your compiler does.
The value of Size can also be specified using an attribute definition clause. For example, the following declarations specify a C99 compatible bool:

## Incorrect usages

A common Ada programming mistake is to assume that specifying 'Size for a type T forces the compiler to allocate exactly this number of bits for objects of this type. This is not true. The specified T'Size will force the compiler to use this size for components in packed arrays and records and in Unchecked_Conversion, but the compiler is still free to allocate more bits for stand-alone objects.
Use 'Size on the object itself to force the object to the specified value.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Component Size
* Ada Programming/Attributes/'Max Size In Storage Elements
* Ada Programming/Attributes/'Value Size (implementation defined)
* Ada Programming/Attributes/'Object Size (implementation defined)

### Ada 83 Reference Manual

* 13.7.2: Representation Attributes
* Annex A: Predefined Language Attributes

### Ada 95 Reference Manual

* 13.3: Operational and Representation Attributes
* Annex K: Language-Defined Attributes

### Ada 2005 Reference Manual

* 13.3: Operational and Representation Attributes
* Annex K: Language-Defined Attributes

### Ada 2012 Reference Manual

* 13.3: Operational and Representation Attributes
* Annex K: Language-Defined Aspects and Attributes

# Ada Programming/Attributes/'Size:3

A common Ada programming mistake is to assume that specifying 'Size for a type T forces the compiler to allocate exactly this number of bits for objects of this type. This is not true. The specified T'Size will force the compiler to use this size for components in packed arrays and records and in Unchecked_Conversion, but the compiler is still free to allocate more bits for stand-alone objects.
Use 'Size on the object itself to force the object to the specified value.

# Ada Programming/Attributes/'Small
## Description

Small of the fixed-point type.
S'Small denotes the small of the type of S. The value of this attribute is of the type universal_real.

## Example
# Ada Programming/Attributes/'Small Denominator
## Description

typ'Small_Denominator for any fixed-point subtype yields the denominator in the representation of typ'Small as a rational number with coprime factors (i.e. as an irreducible fraction).

# Ada Programming/Attributes/'Small Numerator
## Description

typ'Small_Numerator for any fixed-point subtype yields the numerator in the representation of typ'Small as a rational number with coprime factors (i.e. as an irreducible fraction).

# Ada Programming/Attributes/'Storage Pool
## Description

Returns Storage pool of the access subtype.
Denotes the storage pool of the type of S. The type of this attribute is Root_Storage_Pool'Class.

## Example
# Ada Programming/Attributes/'Storage Size
## Description

Number of storage elements reserved for the storage pool.
Denotes the number of storage elements reserved for the task. The value of this attribute is of the type universal_integer. The Storage_Size includes the size of the task's stack, if any. The language does not specify whether or not it includes other storage associated with the task (such as the “task control block” used by some implementations.)

## Example
# Ada Programming/Attributes/'Storage Unit
## Description

Standard'Storage_Unit (Standard is the only allowed prefix) provides the same value as System.Storage_Unit.

# Ada Programming/Attributes/'Stream Size
## Description

Number of bits read from or written to a stream by the default implementations of S’Read and S’Write.
If S is definite, denotes the size (in bits) that the implementation would choose for the following objects of subtype S:
* A record component of subtype S when the record type is packed.
* The formal parameter of an instance of Unchecked_Conversion that converts from subtype S to some other subtype.
If S is indefinite, the meaning is implementation defined. The value of this attribute is of the type universal_integer.

## Example
# Ada Programming/Attributes/'Stub Type
## Description

The GNAT implementation of remote access-to-classwide types is organized as described in AARM section E.4 (20.t): a value of an RACW type (designating a remote object) is represented as a normal access value, pointing to a “stub” object which in turn contains the necessary information to contact the designated remote object. A call on any dispatching operation of such a stub object does the remote call, if necessary, using the information in the stub object to locate the target partition, etc.
For a prefix T that denotes a remote access-to-classwide type, T'Stub_Type denotes the type of the corresponding stub objects.
By construction, the layout of T'Stub_Type is identical to that of type RACW_Stub_Type declared in the internal implementation-defined unit System.Partition_Interface. Use of this attribute will create an implicit dependency on this unit.

# Ada Programming/Attributes/'Succ
## Description

X'Succ(Y) is an Ada attribute where X is any discrete type and Y is a value of that type. This attribute represents the discrete value that has a position number of one greater than the input parameter.
The returned discrete value type is the base type of discrete type. If the input parameter is the Last value of the discrete type, then a CONSTRAINT_ERROR exception will be raised.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes/'Pred

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'System Allocator Alignment
## Description

Standard'System_Allocator_Alignment (Standard is the only allowed prefix) provides the observable guaranteed to be honored by the system allocator (malloc). This is a static value that can be used in user storage pools based on malloc either to reject allocation with alignment too large or to enable a realignment circuitry if the alignment request is larger than this value.

# Ada Programming/Attributes/'Tag
## Description

X'Tag is an Ada attribute where X is any tagged type. This attribute returns a value of the private type Ada.Tags.Tag which identifies the tagged type.
This attribute is useful to check for membership of a type in a class hierarchy. It can also be used if it is known the type is in a class hierarchy and type-specific processing must take place.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Object Orientation
* Ada Programming/Attributes/'Class

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Target Name
## Description

Standard'Target_Name (Standard is the only allowed prefix) provides a static string value that identifies the target for the current compilation. For GCC implementations, this is the standard gcc target name without the terminating slash (for example, GNAT 5.0 on windows yields “i586-pc-mingw32msv”).

# Ada Programming/Attributes/'Task ID
## Description

For a non-passive task object or a value, X, X’TASK_ID yields the unique task ID associated with the task. The value of this attribute is of the type SYSTEM.TASK_ID. If the task objector value X denotes a passive task, the result is the passive task header record object associated with the passive task. The result type is then of type SYSTEM.PASSIVE_TASK_ID.

# Ada Programming/Attributes/'Terminated
## Description

X'Terminated is an Ada attribute where X is any task object. This attribute indicates if X has terminated (true) or not (false).
Be warned—calling X'Terminated can result in a race condition. X'Terminated may be false at the time the attribute value is read, but it may become true at the time action is taken based on the value read. Once X'Terminated is true, however, it can be expected to stay true.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Tasking
* Ada Programming/Attributes/'Callable

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'To Address
## Description

System'To_Address (X) is a GNAT specific attribute with the same purpose of function System.Storage_Elements.To_Address. The only difference is that it can be used in preelaborated units where non-static calls are not allowed. X is a value of that type System.Storage_Elements.Integer_Address (an implementation-defined integer type), and note that this attribute is not applied to the type of X but always to package System.

## Example

Using the standard Ada To_Address function:
Using the GNAT specific To_Address attribute:

## See also
### Wikibook

* Ada Programming
* Ada Programming/Libraries/System.Storage_Elements

### GNAT Reference Manual

* GNAT Implementation Defined Attributes: To_Address

# Ada Programming/Attributes/'To Any
## Description

This internal attribute is used for the generation of remote subprogram stubs in the context of the Distributed Systems Annex.

# Ada Programming/Attributes/'Truncation
## Description

X'Truncation(Y) is an Ada attribute where X is any floating-point type and Y is any instance of that type. This attribute represents the truncation of Y to an integer value.
If Y is negative, then Truncation is equivalent to X'Ceiling(Y). If Y is positive, then Truncation is equivalent to X'Floor(Y).

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Ceiling
* Ada Programming/Attributes/'Floor
* Ada Programming/Attributes/'Rounding
* Ada Programming/Attributes/'Remainder
* Ada Programming/Attributes/'Unbiased_Rounding

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'TypeCode
## Description

This internal attribute is used for the generation of remote subprogram stubs in the context of the Distributed Systems Annex.

# Ada Programming/Attributes/'Type Class
## Description

typ'Type_Class for any type or subtype yields the value of the type class for the full type of . If is a generic formal type, the value is the value for the corresponding actual subtype. The value of this attribute is of type System.Aux_DEC.Type_Class, which has the following definition:
Protected types yield the value Type_Class_Task, which thus applies to all concurrent types. This attribute is designed to be compatible with the DEC Ada 83 attribute of the same name.

# Ada Programming/Attributes/'Type Key
## Description

The Type_Key attribute is applicable to a type or subtype and yields a value of type Standard.String containing encoded information about the type or subtype. This provides improved compatibility with other implementations that support this attribute.

# Ada Programming/Attributes/'Unbiased Rounding
## Description

X'Unbiased_Rounding(Y) is an Ada attribute where X is any floating-point type and Y is any instance of that type. This attribute represents the closest integer value to Y. If Y is exactly between two integer values (e.g. 1.5), then the result is the even value (e.g. 2.0).

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Ceiling
* Ada Programming/Attributes/'Floor
* Ada Programming/Attributes/'Rounding

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Unchecked Access
## Description

Same as X’Access but lacks accessibility rules/checks.
All rules and semantics that apply to X'Access apply also to X'Unchecked_Access, except that, for the purposes of accessibility rules and checks, it is as if X were declared immediately within a library package.

## Example
# Ada Programming/Attributes/'Unconstrained Array
## Description

The Unconstrained_Array attribute can be used with a prefix that denotes any type or subtype. It is a static attribute that yields True if the prefix designates an unconstrained array, and False otherwise. In a generic instance, the result is still static, and yields the result of applying this test to the generic actual.

# Ada Programming/Attributes/'Universal Literal String
## Description

The prefix of Universal_Literal_String must be a named number. The static result is the string consisting of the characters of the number as defined in the original source. This allows the user program to access the actual text of named numbers without intermediate conversions and without the need to enclose the strings in quotes (which would preclude their use as numbers).
For example, the following program prints the first 50 digits of pi:

# Ada Programming/Attributes/'Unrestricted Access
## Description

The Unrestricted_Access attribute is similar to Access except that all accessibility and aliased view checks are omitted. This is a user-beware attribute.
For objects, it is similar to Address, for which it is a desirable replacement where the value desired is an access type. In other words, its effect is similar to first applying the Address attribute and then doing an unchecked conversion to a desired access type.
For subprograms, P'Unrestricted_Access may be used where P'Access would be illegal, to construct a value of a less-nested named access type that designates a more-nested subprogram. This value may be used in indirect calls, so long as the more-nested subprogram still exists; once the subprogram containing it has returned, such calls are erroneous. For example:
When P1 is called from P2, the call via Global is OK, but if P1 were called after P2 returns, it would be an erroneous use of a dangling pointer.
For objects, it is possible to use Unrestricted_Access for any type. However, if the result is of an access-to-unconstrained array subtype, then the resulting pointer has the same scope as the context of the attribute, and must not be returned to some enclosing scope. For instance, if a function uses Unrestricted_Access to create an access-to-unconstrained-array and returns that value to the caller, the result will involve dangling pointers. In addition, it is only valid to create pointers to unconstrained arrays using this attribute if the pointer has the normal default ‘fat’ representation where a pointer has two components, one points to the array and one points to the bounds. If a size clause is used to force ‘thin’ representation for a pointer to unconstrained where there is only space for a single pointer, then the resulting pointer is not usable.
In the simple case where a direct use of Unrestricted_Access attempts to make a thin pointer for a non-aliased object, the compiler will reject the use as illegal, as shown in the following example:
but other cases cannot be detected by the compiler, and are considered to be erroneous. Consider the following example:
A normal unconstrained array value or a constrained array object marked as aliased has the bounds in memory just before the array, so a thin pointer can retrieve both the data and the bounds. But in this case, the non-aliased object X does not have the bounds before the string. If the size clause for type A were not present, then the pointer would be a fat pointer, where one component is a pointer to the bounds, and all would be well. But with the size clause present, the conversion from fat pointer to thin pointer in the call loses the bounds, and so this is erroneous, and the program likely raises a Program_Error exception.
In general, it is advisable to completely avoid mixing the use of thin pointers and the use of Unrestricted_Access where the designated type is an unconstrained array. The use of thin pointers should be restricted to cases of porting legacy code that implicitly assumes the size of pointers, and such code should not in any case be using this attribute.
Another erroneous situation arises if the attribute is applied to a constant. The resulting pointer can be used to access the constant, but the effect of trying to modify a constant in this manner is not well-defined. Consider this example:
Here we attempt to modify the constant P from 4 to 3, but the compiler may or may not notice this attempt, and subsequent references to P may yield either the value 3 or the value 4 or the assignment may blow up if the compiler decides to put P in read-only memory. One particular case where Unrestricted_Access can be used in this way is to modify the value of an in parameter:
In general this is a risky approach. It may appear to “work” but such uses of Unrestricted_Access are potentially non-portable, even from one version of GNAT to another, so are best avoided if possible.

# Ada Programming/Attributes/'Update
## Description

The Update attribute creates a copy of an array or record value with one or more modified components. The syntax is:
where PREFIX is the name of an array or record object, the association list in parentheses does not contain an others choice and the box symbol <> may not appear in any expression. The effect is to yield a copy of the array or record value which is unchanged apart from the components mentioned in the association list, which are changed to the indicated value. The original value of the array or record value is not affected. For example:
yields a value for Avar2 of 1,10,20,20,5 with Avar1 begin unmodified. Similarly:
yields a value for Rvar2 of (A => 1, B => 20, C => 3), with Rvar1 being unmodifed. Note that the value of the attribute reference is computed completely before it is used. This means that if you write:
then the value of Avar1 is not modified if Function_Call raises an exception, unlike the effect of a series of direct assignments to elements of Avar1. In general this requires that two extra complete copies of the object are required, which should be kept in mind when considering efficiency.
The Update attribute cannot be applied to prefixes of a limited type, and cannot reference discriminants in the case of a record type. The accessibility level of an Update attribute result object is defined as for an aggregate.
In the record case, no component can be mentioned more than once. In the array case, two overlapping ranges can appear in the association list, in which case the modifications are processed left to right.
Multi-dimensional arrays can be modified, as shown by this example:
which changes element (1,2) to 20 and (3,4) to 30.

# Ada Programming/Attributes/'VADS Size
## Description

The 'VADS_Size attribute is intended to make it easier to port legacy code which relies on the semantics of 'Size as implemented by the VADS Ada 83 compiler. GNAT makes a best effort at duplicating the same semantic interpretation. In particular, 'VADS_Size applied to a predefined or other primitive type with no Size clause yields the Object_Size (for example, Natural'Size is 32 rather than 31 on typical machines). In addition 'VADS_Size applied to an object gives the result that would be obtained by applying the attribute to the corresponding type.

# Ada Programming/Attributes/'Val
## Description

The 'Val attribute is defined for all discrete types. It is a function returning that value of the base type of S having the argument's position number; the prefix S must be a subtype name. (Any specific integer type is implicitly converted to universal_integer.)
If no value of the type of S has the position number Arg, the Constraint_Error exception is raised.
Note that representation clauses do not affect position numbering. Whatever underlying value the enumerated value has, the position number will remain the same.

## Example

Other example:
The internal representation can only be queried via Unchecked_Conversion.

## See also

The inverse of the 'Val attribute is 'Pos.

### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Pos

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Valid
## Description

Objects may become invalid via import, unchecked conversions, overlays, etc.
The Valid attribute can be used with an object of any scalar type (that is, numeric or enumeration types) to know whether its value is valid (e.g. not out-of-range, etc.). The result is always True or False; neither Constraint_Error nor any other exception are ever raised.
It is important that the evaluation of the attribute does not count as reading the object, whereas reading an invalid object makes the program erroneous.

## Example

Note that in the erroneous assignment statement above, no range check is performed (hence no exception will be raised) since both variables are of the same subtype.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes

### Ada Reference Manual

* 13.9.2: The Valid Attribute

### Ada Quality and Style Guide

* 5.9.1 Unchecked Conversion — Consider using the 'Valid attribute to check the validity of scalar data.
* 5.9.7 Direct_IO and Sequential_IO — Use the 'Valid attribute to check the validity of scalar values obtained through Ada.Direct_IO and Ada.Sequential_IO.
* 6.3.3 The Abort Statement — In the presence of the abort statement, consider using the 'Valid attribute to check the validity of scalar data.

### Ada Rationale

* h.1.1 The Valid Attribute

# Ada Programming/Attributes/'Valid Scalars
## Description

The 'Valid_Scalars attribute is intended to make it easier to check the validity of scalar subcomponents of composite objects. The attribute is defined for any prefix P which denotes an object. Prefix P can be any type except for tagged private or Unchecked_Union types. The value of the attribute is of type Boolean.
P'Valid_Scalars yields True if and only if the evaluation of C'Valid yields True for every scalar subcomponent C of P, or if P has no scalar subcomponents. Attribute 'Valid_Scalars is equivalent to attribute 'Valid for scalar types.
It is not specified in what order the subcomponents are checked, nor whether any more are checked after any one of them is determined to be invalid. If the prefix P is of a class-wide type T'Class (where T is the associated specific type), or if the prefix P is of a specific tagged type T, then only the subcomponents of T are checked; in other words, components of extensions of T are not checked even if T'Class (P)'Tag /= T'Tag.
The compiler will issue a warning if it can be determined at compile time that the prefix of the attribute has no scalar subcomponents.
Note: Valid_Scalars can generate a lot of code, especially in the case of a large variant record. If the attribute is called in many places in the same program applied to objects of the same type, it can reduce program size to write a function with a single use of the attribute, and then call that function from multiple places.

# Ada Programming/Attributes/'Valid Value
## Description

The 'Valid_Value attribute is defined for enumeration types other than those in package Standard. This attribute is a function that takes a String, and returns Boolean. T'Valid_Value (S) returns True if and only if T'Value (S) would not raise Constraint_Error.

# Ada Programming/Attributes/'Value
## Description

The 'Value attribute is defined for any scalar type. This attribute is a function that parses the string and returns the corresponding type value, if it exists. Leading and trailing spaces are trimmed.
If the string does not correspond to any value of the type, then the Constraint_Error exception is raised.
There are corresponding attributes for Wide_String and Wide_Wide_String.
Don't confuse this attribute with the Ada Programming/Attributes/'Val attribute.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Image

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Value Size
## Description

type'Value_Size is the number of bits required to represent a value of the given subtype. It is the same as type'Size, but, unlike Size, may be set for non-first subtypes.

# Ada Programming/Attributes/'Version
## Description

Yields string that identifies the version of the compilation unit that contains the declaration of the program unit.

## Example
# Ada Programming/Attributes/'Wchar T Size
## Description

Standard'Wchar_T_Size (Standard is the only allowed prefix) provides the size in bits of the C wchar_t type primarily for constructing the definition of this type in package Interfaces.C. The result is a static constant.

# Ada Programming/Attributes/'Wide Image
## Description

Image of the value of X as a Wide_String.
S'Wide_Image calls S'Put_Image passing Arg (which will typically store a sequence of character values in a text buffer) and then returns the result of retrieving the contents of that buffer with function Wide_Get.
X'Wide_Image denotes the result of calling function S'Wide_Image with Arg being X, where S is the nominal subtype of X (Ada 2022).

## Example
# Ada Programming/Attributes/'Wide Value
## Description

Returns a value given an image of the value as a Wide_String argument (X).
This function returns a value given an image of the value as a Wide_String, ignoring any leading or trailing spaces.

## Example
# Ada Programming/Attributes/'Wide Wide Image
## Description

Image of the value of X as a Wide_Wide_String.
S'Wide_Wide_Image calls S'Put_Image passing Arg (which will typically store a sequence of character values in a text buffer) and then returns the result of retrieving the contents of that buffer with function Wide_Wide_Get.
X'Wide_Wide_Image denotes the result of calling function S'Wide_Wide_Image with Arg being X, where S is the nominal subtype of X (Ada 2022).

## Example
# Ada Programming/Attributes/'Wide Wide Value
## Description

Returns a value given an image of the value as a Wide_Wide_String argument (X).
This function returns a value given an image of the value as a Wide_Wide_String, ignoring any leading or trailing spaces.

## Example
# Ada Programming/Attributes/'Wide Wide Width
## Description

Maximum length of Wide_Wide_String returned by S’Image.
S'Wide_Wide_Width denotes the maximum length of a Wide_Wide_String returned by S'Wide_Wide_Image over all values of the subtype S, assuming a default implementation of S'Put_Image. It denotes zero for a subtype that has a null range. Its type is universal_integer.

## Example
# Ada Programming/Attributes/'Wide Width
## Description

Maximum length of Wide_String returned by S’Image.
S'Wide_Width denotes the maximum length of a Wide_String returned by S'Wide_Image over all values of the subtype S, assuming a default implementation of S'Put_Image. It denotes zero for a subtype that has a null range. Its type is universal_integer

## Example
# Ada Programming/Attributes/'Width
## Description

X'Width is an Ada attribute where X is any discrete type. This attribute represents the number of characters it takes to represent the "longest" type value using the X'Image attribute.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Image

### Ada Reference Manual

* 13.3 Operational and Representation Attributes (Annotated)
* Annex K Language-Defined Attributes (Annotated)

# Ada Programming/Attributes/'Word Size
## Description

Standard'Word_Size (Standard is the only allowed prefix) provides the value System.Word_Size. The result is a static constant.

# Ada Programming/Attributes/'Write
## Description

Writes X to Stream.

## Example
# Ada Programming/Attributes/'Enum Rep
## Description

This language feature has been introduced in Ada 2022. User_Enum_Type'Enum_Rep(Instance); where User_Enum_Type is an enumeration type and Instance is an instance of that type will return the underlying representation for that instance of the enumeration. The default representation of an enumeration is based on its position (starting at zero). However, Ada does provide language facilities for specifying the representation independently of the position. The Enum_Rep allows you to retrieve that representation. Generally in Ada, enumerations are their own type and the representation is not important. However, in the interests of cross language compatibility and for possible use in embedded programming the representation can be manipulated. While the core language allows you to change the representation, it doesn't provide a convenient attribute for retrieving it. This extended attribute addresses that need. Using it does require that you know the underlying type used to support the enumeration, since Enum_Rep returns that type. Typically, the standard type Integer is sufficient.
Note that this attribute is now standard in Ada 2022. In earlier Ada versions, it is available in GNAT as an implementation defined attribute, but the standard and portable way to get the internal representation was using an instantiation of Unchecked_Conversion.

## See also
### Wikibook

* Ada Programming
* Ada Programming/Attributes
* Ada Programming/Attributes/'Enum_Val

### Ada Reference Manual

* 13.4: Enumeration Representation Clauses
* Annex K: Language-Defined Attributes

### Ada 2022 Overview

* 7.13 Getting the representation of an enumeration value

### External links

GNAT Reference Manual > Implementation Defined Attributes > Enum_Rep