3

I've recently stumbled upon code similar to this, which compiled in Ada 95 mode and not in Ada 2005 mode:

with Ada.Text_IO;

procedure Test is
  
   Printable_Char : constant Character := '["20"]';
   Non_printable_Char : constant Character := '["00"]';
begin
   
   Ada.Text_IO.Put_Line (Printable_Char & Non_printable_Char);
   
end Test;

Using FSG GNAT 9.3.0:

test.adb:6:48: (Ada 2005) non-graphic character not permitted in character literal

But compiles OK using -gnat95 flag (Ada 95 mode).

I found some references of this format in chapter "11.6 Wide Text IO" of GNAT RM. Is this format GNAT specific?

Regarding the difference in the language version mode, I found no mention of it in the Ada 2005 Rationale. Then, why that difference when compiling in Ada 2005 mode?

Gneuromante
  • 560
  • 3
  • 12
  • 3
    This is not legal Ada for any version of the language. I presume this is a GNAT extension. – Jeffrey R. Carter Dec 11 '21 at 12:14
  • 1
    Bracket notation is used in the GCC copy of ACATS 2.6, [c250002.aw](https://github.com/gcc-mirror/gcc/blob/master/gcc/testsuite/ada/acats/tests/c2/c250002.aw) where it’s described as "the brackets scheme for representing Latin-1 character values in transportable 7 bit ASCII as proposed by Robert Dewar" (the current version of this test uses UTF-8). What I can’t find is any official description of the format in the ARM (but then, the standard doesn’t specify the source representation of programs). Nor can I find any AI which justifies the `(Ada 2005)` in the reported error message. – Simon Wright Dec 16 '21 at 13:15

1 Answers1

3

This is documented in the Ada 2012 Language Reference Manual

The pertinent quotation is:

 -- The declaration of type Character is based on the standard ISO 8859-1 character set.

  -- There are no character literals corresponding to the positions for control characters.
  -- They are indicated in italics in this definition. See 3.5.2.
Jim Rogers
  • 4,822
  • 1
  • 11
  • 24
  • The same comment is in the Ada 95 Reference Manual, so that by itself does not explain why the encoding for non-printable character is accepted in Ada 95 and not in Ada 2005. – Gneuromante Dec 10 '21 at 21:25
  • 1
    Try initializing the null character constant as "Non_printable_Char : constant Character := Ada.Characters.Latin_1.NUL;" – Jim Rogers Dec 11 '21 at 02:59
  • Yes, that is what I did, but I wanted to know the reasons behind the change. – Gneuromante Dec 11 '21 at 11:34