comp.lang.ada
 help / color / mirror / Atom feed
* Question on modular types
@ 1997-01-04  0:00 Jerry van Dijk
  1997-01-04  0:00 ` Robert Dewar
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Jerry van Dijk @ 1997-01-04  0:00 UTC (permalink / 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.





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~1997-01-12  0:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-04  0:00 Question on modular types Jerry van Dijk
1997-01-04  0:00 ` 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

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