From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Ada.Containers.Vectors - querying multiple elements
Date: 03 May 2005 19:30:29 -0400
Date: 2005-05-03T19:30:29-04:00 [thread overview]
Message-ID: <wcck6mfhoq2.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: qm04fl5okrie.jqzulrqzezto.dlg@40tude.net
"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> On 02 May 2005 14:57:15 -0400, Robert A Duff wrote:
>
> > "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> >
> >> So "" is not allowed for any string type which index is not a
> >> subtype/derived type S of some base type T, such that S'First>T'First. With
> >> a nice consequence that:
> >>
> >> type T1 is range -2147483647..0;
> > ^^^^^^^^^^
> > You misspelled "-2**31". ;-)
>
> Actually it is 1 - 2**31 (:-)),
Right. Which proves my point, which is that your point would be clearer
if you used "2**31" or whatever instead of putting in a literal.
Without underscores, even!
>... but the point is that it can be any number!
Right.
> The standard is silent about powers of 2.
As well it should be, IMHO.
>... Can I write a compiler with a
> built-in integer type Short_Int which range is -5..5? Is this illegal?
Yes. But the built-in types are irrelevant. What's relevant is the
"base range" of a type. The RM says it has to be (almost) symmetric
about zero. So, yes, if you say "type T is range 2..3" the base range
could be -5..5 (according to the RM).
> >> type T1_Array is array (T range <>) of Character;
> >>
> >> type T2 is range -2147483648..0;
> >> type T2_Array is array (T range <>) of Character;
> >>
> >> type T3 is range -2147483649..0;
> >> type T3_Array is array (T range <>) of Character;
> >>
> >> X : T1_Array := ""; -- Legal
> >> Y : T2_Array := ""; -- Illegal
> >> Z : T3_Array := ""; -- Again legal!!!!!
> >
> > Well, Ada's integer types are intended to be hardware-oriented, for
> > better or worse. This empty-array issue is an extremely rare case.
> > Consider:
> >
> > X1: T1 := T1'First;
> > X2: T2 := T2'First;
> > X3: T3 := T3'First;
> >
> > X1 := (X1-1)/2;
> > X2 := (X2-1)/2;
> > X3 := (X3-1)/2;
> >
> > Which of the above will raise Constraint_Error (due to overflow on the
> > subtraction)? Well it's entirely implementation defined, but given
> > typical hardware and compiler, you'll get the same behavior as with the
> > empty strings.
>
> How would you formally, in the sense ARM 1.1.5, classify the error above
> and one of using empty strings? It seems to me that to rely on
> Constraint_Error above would be a bounded error. But programs using empty
> strings would be illegal Ada programs.
There's no "bounded error" here. These things raise C_E, or return the
correct result. If every intermediate result is in the base range, the
RM requires correct results; otherwise, it allows C_E or correct
results. RM-4.9(34..35) might make some such things illegal -- I'm not
sure. (Illegal = compile-time error.)
> > Seems to me that arithmetic is a more common case. I mean, nobody makes
> > arrays starting near -2**31.
>
> I don't think that statistical approach is appropriate here. Anyway it
> makes an implementation of many generic algorithms and container libraries
> very difficult if possible.
I don't see a big problem here. If you're counting things, use signed
integers, and start counting at zero or one. If you're using enums or
modulars, you're not "counting", and zero-length arrays/vectors/whatever
make no sense.
> > I admit this stuff is a little bit error prone. That's what you get
> > when the language is hardware oriented (for efficiency, of course).
>
> Is this the only way to achieve efficiency?
No. I think I can design an efficent language that doesn't have these
problems. But it ain't Ada.
- Bob
next prev parent reply other threads:[~2005-05-03 23:30 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-26 11:43 Ada.Containers.Vectors - querying multiple elements Duncan Sands
2005-04-26 14:12 ` Georg Bauhaus
2005-04-26 14:39 ` Duncan Sands
2005-04-26 15:44 ` Matthew Heaney
2005-04-26 16:05 ` Duncan Sands
[not found] ` <1114531544.32583.142.camel@localhost.localdomain>
[not found] ` <426E72C3.9070108@on2.com>
2005-04-26 16:59 ` Duncan Sands
[not found] ` <1114534751.32583.144.camel@localhost.localdomain>
[not found] ` <426E73DE.2070505@on2.com>
2005-04-26 17:08 ` Duncan Sands
2005-04-26 18:17 ` Martin Dowie
2005-04-26 18:48 ` Duncan Sands
2005-04-26 18:59 ` Duncan Sands
2005-04-26 19:05 ` Georg Bauhaus
2005-04-26 20:34 ` Duncan Sands
2005-04-26 21:47 ` Dr. Adrian Wrigley
2005-04-26 23:21 ` Marius Amado Alves
[not found] ` <9decddc0038674b3c85aeceefb4d3b83@netcabo.pt>
2005-04-27 8:15 ` Duncan Sands
[not found] ` <1114589729.10418.13.camel@localhost.localdomain>
2005-04-27 11:49 ` Marius Amado Alves
2005-04-28 0:36 ` Randy Brukardt
2005-04-28 7:09 ` Duncan Sands
2005-04-27 11:10 ` Georg Bauhaus
2005-04-27 11:57 ` Duncan Sands
2005-04-28 14:17 ` Duncan Sands
2005-04-27 4:59 ` Jeffrey Carter
2005-04-27 7:21 ` Duncan Sands
2005-04-28 2:54 ` Jeffrey Carter
2005-04-28 7:15 ` Duncan Sands
2005-04-28 12:27 ` Matthew Heaney
2005-04-28 13:18 ` Matthew Heaney
2005-04-28 13:53 ` Duncan Sands
2005-04-29 2:46 ` Jeffrey Carter
2005-04-29 18:22 ` Robert A Duff
2005-04-28 7:18 ` Duncan Sands
2005-04-28 0:33 ` Randy Brukardt
2005-04-28 3:09 ` Jeffrey Carter
2005-04-28 20:55 ` Randy Brukardt
2005-04-29 2:54 ` Jeffrey Carter
2005-04-29 18:34 ` Robert A Duff
2005-04-29 20:18 ` Randy Brukardt
2005-04-29 20:00 ` Randy Brukardt
2005-04-30 4:06 ` Jeffrey Carter
2005-04-29 7:52 ` Dmitry A. Kazakov
2005-04-29 20:26 ` Randy Brukardt
2005-04-30 9:24 ` Dmitry A. Kazakov
2005-05-02 3:21 ` Randy Brukardt
2005-05-02 17:04 ` Dmitry A. Kazakov
2005-05-02 18:57 ` Robert A Duff
2005-05-03 8:14 ` Dmitry A. Kazakov
2005-05-03 23:30 ` Robert A Duff [this message]
2005-05-05 10:51 ` Dmitry A. Kazakov
2005-05-07 1:20 ` Matthew Heaney
2005-05-07 7:17 ` Dmitry A. Kazakov
[not found] <1114515832.32583.41.camel@localhost.localdomain>
[not found] ` <426E5A0B.3010109@on2.com>
2005-04-26 16:00 ` Duncan Sands
2005-04-28 0:54 ` Randy Brukardt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox