Ada Programming/Libraries/Standard

< Ada Programming‎ | Libraries

Ada Lovelace 1838.jpg

The Standard package is implicit. This means two things:

  1. You do not need to with or use the package, in fact you cannot (see below). It's always available (except where hidden by a homograph, RM 8.3 (8) (Annotated)).
  2. Standard may contain constructs which are not quite legal Ada (like the definitions of Character and Wide_Character).

A with clause mentioning Standard references a user-defined package Standard that hides the predefined one. So do not do this. However any library unit hidden by a homograph can be made visible again by qualifying its name with Standard, like e.g. Standard.My_Unit.


Since the package Standard is very important for portability, here are some examples for various compilers:


The only mandatory types in Standard are Boolean, Integer and its subtypes, Float, Character, Wide_Character, Wide_Wide_Character, String, Wide_String, Wide_Wide_String, Duration. There is an implementation permission in RM A.1 (51) (Annotated) that there may be more integer and floating point types and an implementation advice RM A.1 (52) (Annotated) about the names to be chosen. There even is no requirement that those additional types must have different sizes. So it is e.g. legal for an implementation to provide two types Long_Integer and Long_Long_Integer which both have the same range and size.

Note that the ranges and sizes of these types can be different in every platform (except of course for Boolean and [[Wide_]Wide_]Character). There is an implementation requirement that the size of type Integer is at least 16 bits, and that of Long_Integer at least 32 bits (if present) RM 3.5.4 (21..22) (Annotated). So if you want full portability of your types, do not use types from Standard (except where you must, see below), rather define you own types. A compiler will reject any type declaration whose range it cannot satisfy.

This means e.g. if you need a 64-bit type and find that with your current implementation Standard.Long_Long_Integer is such a type, when porting your program to another implementation, this type may be shorter, but the compiler will not tell you - and your program will most probably crash. However, when you define your own type like

type My_Integer_64 is range -(2**63) .. +(2**63 - 1);

then, when porting to an implementation that cannot satisfy this range, the compiler will reject your program.

The type Integer is mandatory when you use [[wide] wide] strings or exponentiation x**i. This is why some projects even define their own strings, but this means throwing out the child with the bath tub. Using Integer with strings and exponentiation will normally not lead to portability issues.

See alsoEdit

Read in another language