comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@mitre-bedford.arpa  (Robert I. Eachus)
Subject: Re: Bug in AdaEd???
Date: 22 Sep 93 21:07:25 GMT	[thread overview]
Message-ID: <EACHUS.93Sep22160725@spectre.mitre.org> (raw)

In article <1993Sep22.093656.20606@sei.cmu.edu> firth@sei.cmu.edu (Robert Firth
) writes:

   > Indeed a nasty example!  However, isn't the solution fairly simple:
   > eliminate the variable Junk and rewrite the test as

   > 	   if X*Y > 10_000 then ...

   > As far as I can see, that has to work regardless of whether X*Y
   > overflows.  Moreover, isn't it the obvious way to write the code?

   That was where we started...I guess I should have used a larger
number in the example.  Substitute 1_000_000 for 10_000 and compile
your code on a 16-bit machine.  Do you see the problem?  The compiler
is allowed to assume the expression is false in all cases without
doing the check, and thus without raising NUMERIC_ERROR or
CONSTRAINT_ERROR on the expression evaluation.  Comparing a variable
to a bound is not a problem, it's this pesky case of an expression
whose value may be out of range of the type.  Assigning the expression
to a variable seems like the solution, but as my original example
pointed out, that is not guarenteeed to work either.

   In practice, for anyone who has to write code like this, assigning
to a global variable, or using pragma VOLITILE on the variable, etc.
works fine.  You get unoptimized code, but in this case that is
precisely what you want.  (And also, this is not just an Ada problem.
I have also run into this "feature" in PL/I and FORTRAN compilers
as well.  In all cases confusing the optimizer was enough to get
working code.  The worry in the ARG is that optimizers are contantly
getting smarter.)

--

					Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...

             reply	other threads:[~1993-09-22 21:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-09-22 21:07 Robert I. Eachus [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-09-23 20:55 Bug in AdaEd??? Tucker Taft
1993-09-23 18:46 Tucker Taft
1993-09-22 22:28 Robert I. Eachus
1993-09-22 14:22 Norm an H. Cohen
1993-09-22 14:10 cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland.reston.ans.net!usc!cs.utexas.edu!not-for-mail
1993-09-22 13:36 cis.ohio-state.edu!news.sei.cmu.edu!firth
1993-09-22 11:45 Wes Groleau x1240 C73-8
1993-09-22  0:21 Robert I. Eachus
1993-09-21  4:19 Gene Ouye
1993-09-07  3:20 Robert Dewar
1993-09-06 14:06 Gene Ouye
replies disabled

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