From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1fa85f3df5841ae1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!newshub.sdsu.edu!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Ada.Containers.Vectors - querying multiple elements Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <426e4c2b$0$7515$9b4e6d93@newsread2.arcor-online.net> <0uYbe.542$BE3.229@newsread2.news.pas.earthlink.net> <1wjh6qsazg3rg$.lupowyuqu0tw$.dlg@40tude.net> <1O2dnYJF_uSxAejfRVn-2Q@megapath.net> <14ts2mrny7fci.emc3y6pqq7za$.dlg@40tude.net> Date: Tue, 3 May 2005 10:14:23 +0200 Message-ID: NNTP-Posting-Date: 03 May 2005 10:14:23 MEST NNTP-Posting-Host: 5c046cc1.newsread2.arcor-online.net X-Trace: DXC=]E0JXo8?0;dUWaeE\nHN0lQ5U85hF6f;djW\KbG]kaMh:cmYYm_h3\cc8P2k On 02 May 2005 14:57:15 -0400, Robert A Duff wrote: > "Dmitry A. Kazakov" 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 (:-)), but the point is that it can be any number! The standard is silent about powers of 2. Can I write a compiler with a built-in integer type Short_Int which range is -5..5? Is this illegal? >> 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. > 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 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? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de