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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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!news.glorb.com!newscon02.news.prodigy.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Ada.Containers.Vectors - querying multiple elements Date: 02 May 2005 14:57:15 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: 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> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1115060235 11203 192.74.137.71 (2 May 2005 18:57:15 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 2 May 2005 18:57:15 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:10881 Date: 2005-05-02T14:57:15-04:00 List-Id: "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". ;-) > 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. Seems to me that arithmetic is a more common case. I mean, nobody makes arrays starting near -2**31. > That's really funny. What is so special in the number -2147483648? Should > it mean that potentially no program that uses negative indices and empty > strings is portable, you never know where *a* built-in integer type may > start? Well, you know *something*. The base range has to be symmetric about zero (or have one extra negative value). And you have control: type T2_Base is range (-2**31)-1..0; subtype T2 is T2_Base range -2**31..0; type T2_Array is array (T2 range <>) of Character; Now you can have empty string literals (presuming your compiler supports signed integers as big as T2_Base). 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). - Bob