comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Selective suppression of warnings --- gnat on GNU/Linux
Date: Wed, 31 Dec 2008 09:55:46 -0500
Date: 2008-12-31T09:55:46-05:00	[thread overview]
Message-ID: <wccprj88kct.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 42ffjg.s9b.ln@hunter.axlog.fr

Jean-Pierre Rosen <rosen@adalog.fr> writes:

> Robert A Duff a �crit :
>> 1.    subtype T is Integer range A..B;
>> 2.    type T is new Integer range A..B;
>> 3.    type T is range A..B;
>> [...] Option 3 is questionable, because of overflow semantics for
>> intermediate
>> results in expressions.  In Pascal, if you say (X+Y)/2, it won't
>> overflow if X+Y is in Integer, but not in A..B.  Same is True in Ada for
>> option 2, but not necessarily for option 3.
> Oh no! Option 2 has exactly the same problem, you just hope that by
> forcing your type to have the same number of bits as Integer (a type you
> know nothing about), there will be enough room for your computations...
>
> If you are worried about overflows (and you use only additions), the
> proper declarations are:
> type Big_Enough is range A .. 2*B;
> subtype T is Big_Enough range A .. B;
>
> Of course, if you compute more than single additions, a real analysis
> has to be done to determine the bounds of Big_Enough.

That's all true, if we're just talking about Ada.

But we're talking about translating Pascal into Ada.
I was making the implicit assumption that Pascal's
Integer is the same as Ada's Integer, which is
likely true.

If that's true, then we must presume that the Pascal
programmer already made sure that calculations won't
overflow, so they won't overflow in Ada Integer, either.
Or else there's a bug in the Pascal code,
and we're going to translate that into the same
bug in the Ada code.

If you don't like the above assumption, then I'd say
the correct translation is:

    type Pascal_Integer is range ...;
    subtype T is Pascal_Integer range A..B;

where the rangs of Pascal_Integer is chosen to
match the Pascal compiler -- obviously you have
to know something about the Pascal compiler.

Either way (whether we use Integer or a special
Pascal_Integer), there's no need to analyze the
program for overflow, and do things like the 2*B
you suggest -- that's not the job of a Pascal-to-Ada
translator!

> By all means, please, let's get rid of Integer!

I'm all for it.  ;-)

- Bob



  reply	other threads:[~2008-12-31 14:55 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-30  3:13 Selective suppression of warnings --- gnat on GNU/Linux Michael Mounteney
2008-12-30  8:03 ` Ludovic Brenta
2008-12-30 22:49   ` Michael Mounteney
2008-12-30 23:26     ` Robert A Duff
2008-12-30 11:01 ` (see below)
2008-12-30 11:37   ` Georg Bauhaus
2008-12-30 12:05     ` (see below)
2008-12-30 14:11       ` Pascal ranges (was: Selective suppression of warnings --- gnat on GNU/Linux) Georg Bauhaus
2008-12-30 20:19         ` (see below)
2008-12-30 23:19           ` Pascal ranges Robert A Duff
2008-12-30 23:34             ` (see below)
2008-12-31  0:07               ` Robert A Duff
2008-12-31  0:32                 ` (see below)
2008-12-30 23:13 ` Selective suppression of warnings --- gnat on GNU/Linux Robert A Duff
2008-12-31  9:46   ` Jean-Pierre Rosen
2008-12-31 14:55     ` Robert A Duff [this message]
2008-12-31 16:13       ` Jean-Pierre Rosen
2008-12-31 20:01         ` Robert A Duff
2008-12-31 18:43     ` (see below)
2008-12-31 19:49       ` Robert A Duff
2008-12-31 20:24         ` Jeffrey R. Carter
2008-12-31 22:38           ` Robert A Duff
2008-12-31 19:46 ` Jerry
2008-12-31 22:39   ` Robert A Duff
2008-12-31 23:37   ` Michael Mounteney
2009-01-01  9:45   ` sjw
replies disabled

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