comp.lang.ada
 help / color / mirror / Atom feed
From: "Jerry van Dijk" <jvandyk@ibm.net>
Subject: Question on modular types
Date: 1997/01/04
Date: 1997-01-04T00:00:00+00:00	[thread overview]
Message-ID: <01bbfa96$66d516a0$8d2d5c8b@jerryware> (raw)


Much to my supprise, the following compiles and runs:

   with Ada.Text_IO; use Ada.Text_IO;
   with Interfaces.C; use Interfaces.C;

   procedure Test is

      type My_Int is mod 2 ** 32;

      uint  : unsigned;
      A_Int : My_Int;

   begin

      uint := -1;                         -- Well, its a C type... :-)
      if uint'Valid then
         Put_Line ("uint Valid");
      else
         Put_Line ("uint Invalid");
      end if;

      A_Int := -1;                        -- (A)
      if A_Int'Valid then
         Put_Line ("A_Int Valid");
      else
         Put_Line ("A_Int Invalid");
      end if;

      A_Int := My_Int (uint);             -- (B)
      if A_Int'Valid then
         Put_Line ("A_Int Valid");
      else
         Put_Line ("A_Int Invalid");
      end if;

      if A_Int = -1 then                  -- Compare works ???
         Put_Line ("A_Int is -1 !?!");
      else
         Put_Line ("A_Int is" & A_Int'Img);
      end if;

   end Test;

Clearly, all values are invalid, and that without inporting any values
from the outside world.

I expected the line marked (A) to give an compilation error because of
3.5.4(10) or else the line marked (B) to generate a constraint error
because of 3.5.4(19).

I suspect that (B) doesn't fail since type_conversion is not one of the
operations mentioned in 4.5, and that (A) doesn't result in an error
because of the second sentence in 3.5.4(10) since its base type is
Integer
according to 3.5.4(1).

Still, its not what I expected, so perhaps does someone has an
explantion ?

(BTW using GNAT 3.05 on DOS and 3.07 on Linux, with -gnato)

Thanks,
Jerry.





             reply	other threads:[~1997-01-04  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-04  0:00 Jerry van Dijk [this message]
1997-01-04  0:00 ` Question on modular types Robert Dewar
1997-01-06  0:00   ` Jerry van Dijk
1997-01-06  0:00     ` Robert A Duff
1997-01-08  0:00       ` Robert Dewar
1997-01-09  0:00         ` Tucker Taft
1997-01-11  0:00           ` Robert Dewar
1997-01-12  0:00             ` Joel VanLaven
1997-01-09  0:00         ` Robert A Duff
1997-01-06  0:00 ` Joel VanLaven
1997-01-08  0:00 ` Stan and/or Jill Grimes
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox