Ada Programming/Attributes
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. Aspects and attributes are defined in the Ada Reference Manual annex Annex K: Language-Defined Aspects and Attributes [Annotated].
Language summary attributes Edit
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
Byteis
range
-128 .. 127; -- The range fits into 8 bits but the -- compiler is still free to choose.for
Byte'Sizeuse
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 S : String := Character'(')')'Image; -- an especially nice parsing exercise
List of language defined attributes Edit
- 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 Edit
C Edit
D – F Edit
- 'Definite
- 'Delta
- 'Denorm
- 'Digits
- 'Emax (Obsolescent)
- 'Exponent
- 'External_Tag
- 'Epsilon (Obsolescent)
- 'First
- 'First_Bit
- 'Floor
- 'Fore
- 'Fraction
G – L Edit
- 'Has_Same_Storage (Ada 2012)
- 'Identity
- 'Image
- 'Input
- 'Large (Obsolescent)
- 'Last
- 'Last_Bit
- 'Leading_Part
- 'Length
M Edit
- '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 Edit
- '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 Edit
- '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 Edit
W – Z Edit
- '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 Edit
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 Edit
- '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 Edit
- '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 Edit
- '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 Edit
- '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 Edit
- '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)