411 REFERENCE · Wikibooks
Ada Programming/Attributes/'Image
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
Attributes 'Image
__TOC__
Description
X'Image(Y) is an Ada attribute where X is any discrete type and Y is an instance of that type. This attribute returns a string representation of the value passed as input.
This attribute is a useful way to automatically convert from a type value to a string suitable for output.
In Ada 2022 a simplified version was added:
Y’Image return String
Image of the value of Y as a String.
Example
type My_Enum is (Enum1, Enum2, Enum3);
...
pragma Assert (My_Enum'Image (Enum1) = "ENUM1");
pragma Assert (Enum1'Image = "ENUM1"); -- Ada 2022
See also
Wikibook
Ada Programming
Ada Programming/Attributes
Ada Programming/Attributes/'Value
Ada Reference Manual
13 3 Operational and Representation Attributes
K Language-Defined Attributes
Image