From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: 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.846162354@merv> (raw)
Here is an entertaining little bit of error message stuff in GNAT. Someone
submitted the following program, shown with its original message:
1. procedure t is
2. begin
3. if not 7 < 5 then
|
>>> no modular type available in this context
4. null;
5. end if;
6. end;
Well, that error message is "correct", the expression "not 7" cannot
be resolved. But it sure is confusing. The latest version of GNAT (3.08)
gives:
1. procedure t is
2. begin
3. if not 7 < 5 then
|
>>> operand of not must be enclosed in parentheses
4. null;
5. end if;
6.
7. if (not 7) < 5 then
|
>>> no modular type available in this context
8. null;
9. end if;
10.
11. end;
I have added the parenthesized case here to make sure we do the right thing!
Now, a worse case, suppose that we *are* dealing with modular types, well
then the extension of Ada 95 to allow not on such types has added a real
pitfall to the language. Ada does not have many pitfalls. I mean by pitfall
a case where you write something that looks reasonable, is legal and executes
but does something completely different from what you expect (e.g. in
C the case of if ("abc"=="abc") yielding false).
Consider this program, which we now, as you see, generate a warning for:
1. with Text_IO; use Text_IO;
2. procedure t1 is
3. type m is mod 256;
4. a : m := 4;
5. b : m := 5;
6. begin
7. if not a < b then
|
>>> warning: operand of not operator should be parenthesized
8. Put_Line ("this is what I expect");
9. else
10. Put_Line ("but this is what I get!");
11. end if;
12.
13. if (not a) < b then
14. Put_Line ("this is not what I expect");
15. else
16. Put_Line ("this is what I get, and I really asked for it!");
17. end if;
18. end;
I think this warning is quite reasonable, since I would *really* like people
to use parens if they really want the situation shown on line 13!
next 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 Robert Dewar [this message]
1996-10-24 0:00 ` GNAT messages and the not operator (pitfall alert!) Robert Dewar
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 ` Robert Dewar
1996-10-29 0:00 ` John Herro
1996-10-29 0:00 ` Robert Dewar
1996-10-26 0:00 ` Matthew Heaney
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