comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: GNAT messages and the not operator (pitfall alert!)
Date: 1996/10/24
Date: 1996-10-24T00:00:00+00:00	[thread overview]
Message-ID: <dewar.846163972@merv> (raw)
In-Reply-To: dewar.846162354@merv


Here is another pitfall, pretty horrible if it hits, but fortunately rare.
Ask an Ada expert what is the value of

    -5 mod 3

Almost anyone (the better they know Ada, the more likely they are to make
this mistake) will strain to remember the table in the RM that talks about
negative mods, and, if they remember it right, come up with the answer of 1.
But Ada has VERY odd precedence rules which mean that the default
parenthesiztion of this expression is -(5 mod 3). The only person I
ever knew to get this right (and remember this is under conditions they
know they are being asked to answer a trick question) was Robert Eachus
(both Jean and Tuck got this wrong originally, and so did I :-)

A rare error, since this is unusual usage, but still it seems worth another
warning (incidentally, try these programs on your own compiler and see what
it does -- versions of GNAT before 3.08 are not much help, how do other
compilers do :-)

Incidentally, this is not a zero probability occurrence, we actually had
someone run into this bug recently! Here is the output of GNAT 3.08 on
an example program:

     1. with Text_IO; use Text_IO;
     2. procedure t2 is
     3.    a : integer := 5;
     4.    b : integer := 3;
     5.
     6. begin
     7.    if -5 mod 3 /= 1 then
              |
        >>> warning: unary minus expression should be parenthesized here

     8.       Put_Line ("Table in RM for negative mods is screwed up");
     9.    end if;
    10.
    11.    if (-5) mod 3 /= 1 then
    12.       null;
    13.    else
    14.       Put_Line ("No it isn't!");
    15.    end if;
    16. end;





  reply	other threads:[~1996-10-24  0:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-10-24  0:00 GNAT messages and the not operator (pitfall alert!) Robert Dewar
1996-10-24  0:00 ` Robert Dewar [this message]
1996-10-25  0:00   ` whiting_ms@corning.com (Matt Whiting)
1996-10-26  0:00     ` David C. Hoos, Sr.
1996-10-27  0:00     ` Robert Dewar
1996-10-28  0:00       ` Matthew S. Whiting
1996-10-26  0:00   ` John Herro
1996-10-26  0:00     ` Matthew Heaney
1996-10-29  0:00       ` Robert Dewar
1996-10-26  0:00     ` Robert Dewar
1996-10-29  0:00       ` John Herro
1996-10-29  0:00         ` Robert Dewar
1996-10-30  0:00     ` Dr. Peter E. Obermayer
1996-10-30  0:00       ` John Herro
1996-10-30  0:00         ` Robert Dewar
1996-11-01  0:00         ` User Password expiration date extractor? Stein-Aksel Basma
1996-10-29  0:00   ` GNAT messages and the not operator (pitfall alert!) Norman H. Cohen
1996-10-29  0:00     ` whiting_ms@corning.com (Matt Whiting)
1996-10-30  0:00       ` Robert Dewar
1996-10-30  0:00       ` Norman H. Cohen
1996-11-06  0:00         ` Richard A. O'Keefe
1996-11-18  0:00           ` Norman H. Cohen
1996-11-18  0:00             ` Robert Dewar
1996-10-30  0:00       ` David C. Hoos, Sr.
1996-10-30  0:00         ` whiting_ms@corning.com (Matt Whiting)
1996-10-30  0:00           ` Norman H. Cohen
1996-11-05  0:00     ` Robert Dewar
1996-10-28  0:00 ` Cary Jamison
1996-10-29  0:00   ` Robert Dewar
replies disabled

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