comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: Question on modular types
Date: 1997/01/04
Date: 1997-01-04T00:00:00+00:00	[thread overview]
Message-ID: <dewar.852430006@merv> (raw)
In-Reply-To: 01bbfa96$66d516a0$8d2d5c8b@jerryware


Jerry said

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

No! If it is clear to you, you need your Ada prescription fixed :-)

   A := -1;

-1 is not a literal here, it is an expression, and the unary minus
operator is a modular unary minus. This is a useful, intended, and
clearly documented facility.

Note that if you did

    Minus1 : constant := -1;

    uint := minus1;

then you would get the constraint error:

     1. procedure b is
     2.    type x is mod 256;
     3.    k : constant := -1;
     4.    r : x;
     5.
     6. begin
     7.    r := -1;
     8.    r := k;
                |
        >>> value not in range of type "x" defined at line 2
        >>> static expression raises "constraint_error"

     9. end;

That's because the minus operator in line 3 is the one that works on
root integer (I would really prefer to say universal integer, but I
think root integer is correct), and really does give minus one, and
that is indeed out of range, as detected (statically in this particular
case).

Note that for modular types of sizes corresponding to hardware sizes
(typically 8,16,32) there will of course be no invalid values ever.





  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 Question on modular types Jerry van Dijk
1997-01-04  0:00 ` Robert Dewar [this message]
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         ` Robert A Duff
1997-01-09  0:00         ` Tucker Taft
1997-01-11  0:00           ` Robert Dewar
1997-01-12  0:00             ` Joel VanLaven
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