Ada Programming/Libraries/Standard


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).
Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.

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.

Implementation

edit

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

Portability

edit

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 [Annotated](51) that there may be more integer and floating point types and an implementation advice RM A.1 [Annotated](52) 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 the numeric types can be different in every platform. 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 [Annotated](21..22). There is also an implementation permission RM 3.5.4 [Annotated](25) that further types whose names indicate smaller ranges like Short_Integer (if present) do not in fact have ranges greater than those indicating larger ranges. There is, however, an implementation advice RM 3.5.4 [Annotated](28) that there should be no other integer types in Standard than Integer and Long_Integer; instead, those hardware adapted types should be defined in package Interfaces RM B.2 [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 also

edit

Wikibook

edit

Ada Reference Manual

edit

Ada Quality and Style Guide

edit