Note that 'Image
can incur implementation defined results (RM 3.5), namely when some graphic characters needed for the String
result are not defined in Character
. Consider the larger repertoires of 'Wide_Image
and 'Wide_Wide_Image
.
The permission to use the attribute __Scalar_Object__'Image
directly on an object was added in Ada 2012-TC-1 (April 2016).
with Ada.Text_IO;
procedure Main is
type Some_Float digits 8 range 0.0 .. 10.0;
X : Some_Float := 2.71;
begin
Ada.Text_IO.Put_Line (X'Image);
end Main;
2.71000E+00
with Ada.Text_IO;
procedure Main is
type Some_Integer is range -42 .. 42;
X : Some_Integer := 17;
begin
Ada.Text_IO.Put_Line (X'Image);
end Main;
17
with Ada.Text_IO;
procedure Main is
type Fruit is (Banana, Orange, Pear);
X : Fruit := Orange;
begin
Ada.Text_IO.Put_Line (X'Image);
Ada.Text_IO.Put_Line (Pear'Image);
end Main;
ORANGE
PEAR
with Ada.Text_IO;
procedure Main is
type Fruit is (Banana, Orange, Pear);
X : Fruit := Orange;
begin
Ada.Text_IO.Put_Line (Fruit'Image (X));
end Main;
ORANGE
with Ada.Text_IO;
procedure Main is
X : Integer := 17;
begin
Ada.Text_IO.Put_Line (Integer'Image (X));
end Main;
17
with Ada.Text_IO;
procedure Main is
X : Float := 2.71;
begin
Ada.Text_IO.Put_Line (Float'Image (X));
end Main;
2.71000E+00
with Ada.Text_IO;
procedure Image_And_Value is
type Fruit is (Banana, Orange, Pear);
X : Fruit := Orange;
begin
Ada.Text_IO.Put_Line (Boolean'Image
(Fruit'Value (Fruit'Image (X)) = X
and
Fruit'Image (Fruit'Value ("ORANGE")) = "ORANGE"));
end Image_And_Value;
TRUE