Ada Programming/Attributes
< Ada Programming
Language summary attributes
The concept of attributes is pretty unique to Ada. Attributes allow you to get —and sometimes set— information about objects or other language entities such as types. A good example is the Size attribute. It describes the size of an object or a type in bits.
A : Natural := Integer'Size; -- A is now 32 (with the GNAT compiler for the x86 architecture)
However, unlike the sizeof operator from C/C++ the Size attribute can also be set:
type Byte is range -128 .. 127; -- The range fits into 8 bits but the -- compiler is still free to choose. for Byte'Size use 8; -- Now we force the compiler to use 8 bits.
Of course not all attributes can be set. An attribute starts with a tick ' and is followed by its name. The compiler determines by context if the tick is the beginning of an attribute, a character literal or a quantified expression.
A : Character := Character'Val (32) -- A is now a space B : Character := ' '; -- B is also a space
List of language defined attributes
- Ada 2005
- This is a new Ada 2005 attribute.
- Ada 2012
- This is a new Ada 2012 attribute.
- Obsolescent
- This is a deprecated attribute and should not be used in new code.
A – B
- 'Access
- 'Address
- 'Adjacent
- 'Aft
- 'Alignment
- 'Base
- 'Bit_Order
- 'Body_Version
C
- 'Callable
- 'Caller
- 'Ceiling
- 'Class
- 'Component_Size
- 'Compose
- 'Constrained
- 'Copy_Sign
- 'Count
D – F
- 'Definite
- 'Delta
- 'Denorm
- 'Digits
- 'Emax (Obsolescent)
- 'Exponent
- 'External_Tag
- 'Epsilon (Obsolescent)
- 'First
- 'First_Bit
- 'Floor
- 'Fore
- 'Fraction
G – L
- 'Has_Same_Storage (Ada 2012)
- 'Identity
- 'Image
- 'Input
- 'Large (Obsolescent)
- 'Last
- 'Last_Bit
- 'Leading_Part
- 'Length
M
- 'Machine
- 'Machine_Emax
- 'Machine_Emin
- 'Machine_Mantissa
- 'Machine_Overflows
- 'Machine_Radix
- 'Machine_Rounding (Ada 2005)
- 'Machine_Rounds
- 'Mantissa (Obsolescent)
- 'Max
- 'Max_Alignment_For_Allocation (Ada 2012)
- 'Max_Size_In_Storage_Elements
- 'Min
- 'Mod (Ada 2005)
- 'Model
- 'Model_Emin
- 'Model_Epsilon
- 'Model_Mantissa
- 'Model_Small
- 'Modulus
O – R
- 'Old (Ada 2012)
- 'Output
- 'Overlaps_Storage (Ada 2012)
- 'Partition_ID
- 'Pos
- 'Position
- 'Pred
- 'Priority (Ada 2005)
- 'Range
- 'Read
- 'Remainder
- 'Result (Ada 2012)
- 'Round
- 'Rounding
S
- 'Safe_Emax (Obsolescent)
- 'Safe_First
- 'Safe_Large (Obsolescent)
- 'Safe_Last
- 'Safe_Small (Obsolescent)
- 'Scale
- 'Scaling
- 'Signed_Zeros
- 'Size
- 'Small
- 'Storage_Pool
- 'Storage_Size
- 'Stream_Size (Ada 2005)
- 'Succ
T – V
- 'Tag
- 'Terminated
- 'Truncation
- 'Unbiased_Rounding
- 'Unchecked_Access
- 'Val
- 'Valid
- 'Value
- 'Version
W – Z
- 'Wide_Image
- 'Wide_Value
- 'Wide_Wide_Image (Ada 2005)
- 'Wide_Wide_Value (Ada 2005)
- 'Wide_Wide_Width (Ada 2005)
- 'Wide_Width
- 'Width
- 'Write
List of implementation defined attributes
The following attributes are not available in all Ada compilers, only in those that had implemented them.
Currently, there are only listed the implementation-defined attributes of a few compilers. You can help Wikibooks adding specific attributes of other compilers:
- GNAT
- Implementation-defined attribute of the GNAT compiler from AdaCore/FSF.
- HP Ada
- Implementation-defined attribute of the HP Ada compiler (formerly known as "DEC Ada").
- ICC
- Implementation-defined attribute[1] of the Irvine ICC compiler.
- PowerAda
- Implementation-defined attribute of OC Systems' PowerAda.
- SPARCompiler
- Implementation-defined attribute of Sun's SPARCompiler Ada.
A – D
- 'Abort_Signal (GNAT)
- 'Address_Size (GNAT)
- 'Architecture (ICC)
- 'Asm_Input (GNAT)
- 'Asm_Output (GNAT)
- 'AST_Entry (GNAT, HP Ada)
- 'Bit (GNAT, HP Ada)
- 'Bit_Position (GNAT)
- 'CG_Mode (ICC)
- 'Code_Address (GNAT)
- 'Compiler_Key (SPARCompiler)
- 'Compiler_Version (SPARCompiler)
- 'Declared (ICC)
- 'Default_Bit_Order (GNAT)
- 'Dope_Address (SPARCompiler)
- 'Dope_Size (SPARCompiler)
E – H
- 'Elaborated (GNAT)
- 'Elab_Body (GNAT)
- 'Elab_Spec (GNAT)
- 'Emax (GNAT)
- 'Enabled (GNAT)
- 'Entry_Number (SPARCompiler)
- 'Enum_Rep (GNAT)
- 'Enum_Val (GNAT)
- 'Epsilon (GNAT)
- 'Exception_Address (ICC)
- 'Extended_Aft (PowerAda)
- 'Extended_Base (PowerAda)
- 'Extended_Digits (PowerAda)
- 'Extended_Fore (PowerAda)
- 'Extended_Image (PowerAda)
- 'Extended_Value (PowerAda)
- 'Extended_Width (PowerAda)
- 'Extended_Wide_Image (PowerAda)
- 'Extended_Wide_Value (PowerAda)
- 'Extended_Wide_Width (PowerAda)
- 'Fixed_Value (GNAT)
- 'Has_Access_Values (GNAT)
- 'Has_Discriminants (GNAT)
- 'High_Word (ICC)
- 'Homogeneous (SPARCompiler)
I – N
- 'Img (GNAT)
- 'Integer_Value (GNAT)
- 'Invalid_Value (GNAT)
- 'Linear_Address (ICC)
- 'Low_Word (ICC)
- 'Machine_Size (GNAT, HP Ada)
- 'Max_Interrupt_Priority (GNAT)
- 'Max_Priority (GNAT)
- 'Maximum_Alignment (GNAT)
- 'Mechanism_Code (GNAT)
- 'Null_Parameter (GNAT, HP Ada)
O – T
- 'Object_Size (GNAT)
- 'Old (GNAT)
- 'Passed_By_Reference (GNAT)
- 'Pool_Address (GNAT)
- 'Range_Length (GNAT)
- 'Ref (SPARCompiler)
- 'Storage_Unit (GNAT)
- 'Stub_Type (GNAT)
- 'Target (ICC)
- 'Target_Name (GNAT)
- 'Task_ID (SPARCompiler)
- 'Tick (GNAT)
- 'To_Address (GNAT)
- 'Type_Class (GNAT, HP Ada)
- 'Type_Key (SPARCompiler)
U – Z
- 'UET_Address (GNAT)
- 'Unconstrained_Array (GNAT)
- 'Universal_Literal_String (GNAT)
- 'Unrestricted_Access (GNAT, ICC)
- 'VADS_Size (GNAT)
- 'Value_Size (GNAT)
- 'Wchar_T_Size (GNAT)
- 'Word_Size (GNAT)
See also
Wikibook
Ada Reference Manual
Ada 83
Ada 95
Ada 2005
Ada 2012
References
- ↑ "4.2 ICC-Defined Attributes", ICC Ada Implementation Reference — ICC Ada Version 8.2.5 for i960MC Targets, document version 2.11.4