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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5037bf0bb33408c8 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-08 09:42:57 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!news.tufts.edu!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: "&" for array versus "&" for Strings User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Tue, 8 Oct 2002 16:41:43 GMT Content-Type: text/plain; charset=us-ascii References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:29594 Date: 2002-10-08T16:41:43+00:00 List-Id: "Grein, Christoph" writes: > > ------------------------------------------------------------------ > > with Ada.Text_IO; use Ada.Text_IO; > > procedure Array_Test is > > > > type Name_Array is array (Positive range <>) of String (1..6); > > > > procedure Print_Names (Names : Name_Array) is > > begin > > for No in Names'First .. Names'Last loop > > Put_Line (Integer'Image(No) & ": " & Names (No)); > > end loop; > > end; > > > > begin > > > > Print_Names ("Ada " & "Babbel"); > > > > end Array_Test; > > ------------------------------------------------------------------ > > > > Then the result becomes: > > > > 1: A 2: d 3: a 4: 5: 6: 7: B 8: a 9: b 10: b 11: e 12: l > > Why is this happening. Sounds like a compiler bug. > Which compiler do you use? > > Gnat 3.16w produces an error for this: > > preben.adb:15:17: expected type "Name_Array" defined at line 4 > preben.adb:15:17: found a string type > > With qualification, it works. > > Print_Names (string'("Ada ") & string'("Babbel")); > > The problem cause needs an intensive RM exegesis, which I have just not the time > for. Could be a compiler error. That sounds like a different compiler bug. It seems to me that the "&" should resolve to the (string, string)-->Name_Array one, even without the "String'(...)" qualifications. Apparently, the older compiler resolved it to the wrong one, and the newer one can't resolve it (which is an improvement, but still a bug). I'm not surprised that such a bug has never been noticed before. Most people don't write code that uses "&" to concatenate two Strings to produce something other than String! First, it's confusing (to humans, I mean, in addition to compilers). Second, it requires fixed-length strings, which is almost never what you want in an array. - Bob