Ada types
last modified November 23, 2026
Ada is strongly typed. Every expression has a type, every variable is declared with a type, and the compiler rejects operations that mix types without an explicit conversion. The predefined types cover integers, floating-point numbers, truth values, characters, and strings. This article introduces those types and shows how values move between them.
The predefined types
Integer holds whole numbers, Float holds
floating-point numbers, Boolean holds True and
False, Character holds one character, and
String holds a sequence of characters. Each declaration names the
type first and the variable second, and := gives the initial
value. The attributes 'Image convert a value to a string for
printing.
with Ada.Text_IO;
use Ada.Text_IO;
procedure Types is
Count : Integer := 41;
Price : Float := 2.0;
Letter : Character := 'A';
Word : String := "Ada";
begin
Count := Count + 1;
Price := Price + 0.5;
Letter := 'B';
Word := "Bob";
Put_Line ("integer:" & Integer'Image (Count));
Put_Line ("float:" & Float'Image (Price));
Put_Line ("character:" & Letter);
Put_Line ("string:" & Word);
for I in 1 .. 2 loop
Put_Line ("boolean: " & Boolean'Image (I = 1));
end loop;
end Types;
The assignments update each variable before it is printed, so the output shows
the new values. Float'Image uses a default scientific notation
with six significant digits, which is why 2.5 appears as
2.50000E+00. Boolean'Image writes TRUE
or FALSE in upper case, and a character can be joined directly to
a string with &.
$ gnatmake -gnat2022 -gnatwa types.adb $ ./types integer: 42 float: 2.50000E+00 character:B string:Bob boolean: TRUE boolean: FALSE
No implicit conversion
Integer and Float are distinct types, and a value of
one is not automatically converted to the other. The following declaration
looks harmless in languages that mix numeric types, but Ada rejects it. The
compiler requires the programmer to state the conversion, because the
conversion may lose information.
with Ada.Text_IO; use Ada.Text_IO; procedure Implicit is Count : Integer := 5; Price : Float := Count; begin Put_Line (Float'Image (Price)); end Implicit;
The error names both types and their package, Standard. It does
not mean that the program is badly designed; it means that the conversion must
be written. The same rule applies to Character and
String, to different integer types, and to the numeric types that
a program declares for itself.
$ gnatmake -gnat2022 -gnatwa implicit.adb x86_64-linux-gnu-gcc-14 -c -gnat2022 -gnatwa implicit.adb implicit.adb:6:21: error: expected type "Standard.Float" implicit.adb:6:21: error: found type "Standard.Integer" gnatmake: "implicit.adb" compilation error
Explicit conversions
A conversion is written as a type name followed by the value in parentheses:
Float (Count) converts an integer to a float, and
Integer (Price) converts a float to an integer. The float-to-
integer conversion rounds to the nearest integer and checks that the result is
in range. It does not silently wrap around.
with Ada.Text_IO;
use Ada.Text_IO;
procedure Convert is
Count : Integer := 7;
Price : Float := 2.75;
begin
Price := Float (Count) + Price;
Count := Integer (Price);
Put_Line ("price =" & Float'Image (Price));
Put_Line ("count =" & Integer'Image (Count));
end Convert;
Float (Count) produces 7.0, which is added to 2.75 to give 9.75.
Integer (Price) then rounds 9.75 to 10, not to 9. Ada rounds
instead of truncating, so a conversion can increase the magnitude of a
positive value. A value outside the range of the target type raises
Constraint_Error at run time.
$ gnatmake -gnat2022 -gnatwa convert.adb $ ./convert price = 9.75000E+00 count = 10
Boolean values
A Boolean is the result of a comparison or a logical operation.
The operators and, or, and not combine
truth values, and relational operators such as >= and
< bind more tightly than and. The short-circuit
forms and then and or else are covered with the other
operators later in the series.
with Ada.Text_IO;
use Ada.Text_IO;
procedure Boolean_Demo is
begin
for Age in 16 .. 20 loop
Put_Line ("age =" & Integer'Image (Age));
Put_Line ("adult = " & Boolean'Image (Age >= 18));
Put_Line ("allowed = " & Boolean'Image (Age >= 18 and Age < 20));
if Age >= 18 and Age < 20 then
Put_Line ("entry granted");
end if;
end loop;
end Boolean_Demo;
The loop tests five ages. adult is true from 18 upward, while
allowed is true only from 18 to 19, so the last age is an adult
who is not allowed. The condition in the if repeats the
allowed expression instead of naming it, which keeps the example
short; a separate Boolean variable would read better in a larger program.
$ gnatmake -gnat2022 -gnatwa boolean_demo.adb $ ./boolean_demo age = 16 adult = FALSE allowed = FALSE age = 17 adult = FALSE allowed = FALSE age = 18 adult = TRUE allowed = TRUE entry granted age = 19 adult = TRUE allowed = TRUE entry granted age = 20 adult = TRUE allowed = FALSE
Characters and strings
A character literal is one character between single quotes, as in
'A' or '7'. A string literal is enclosed in double
quotes and may contain several characters. Put has an overload
for a single character, while Put_Line takes a string; to print a
character on its own line, call Put and then
New_Line.
with Ada.Text_IO;
use Ada.Text_IO;
procedure Characters is
Letter : Character;
Digit : Character;
Name : String := "Ada";
begin
Letter := 'A';
Digit := '7';
Name := "Bob";
Put ("letter: ");
Put (Letter);
New_Line;
Put ("digit: ");
Put (Digit);
New_Line;
Put_Line ("name: " & Name);
Put_Line ("greeting: " & Name & "!");
end Characters;
Letter and Digit are assigned before they are read,
and Name is replaced by another string of the same length. A
String variable initialized from a literal is constrained to that
literal's length, so assigning a three-character string to a variable that
started with three characters is allowed; a longer string would raise
Constraint_Error. Unconstrained strings and arrays are covered in
the arrays article.
$ gnatmake -gnat2022 -gnatwa characters.adb $ ./characters letter: A digit: 7 name: Bob greeting: Bob!
Next steps
The variables and constants article explains which declarations keep their value and which can change. The literals article describes every form a value can take in the source text, including based numbers and strings with quotes.
Source
In this article we have declared values of the five predefined types, seen the compiler reject an implicit conversion, converted explicitly with rounding, and combined Boolean, character, and string values. The next article explains how declarations keep or change those values.
Author
List all Ada tutorials.