comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: "&" for array versus "&" for Strings
Date: Tue, 8 Oct 2002 16:41:43 GMT
Date: 2002-10-08T16:41:43+00:00	[thread overview]
Message-ID: <wcc7kgsc27s.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: mailman.1034078403.25693.comp.lang.ada@ada.eu.org

"Grein, Christoph" <christoph.grein@eurocopter.com> 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



  parent reply	other threads:[~2002-10-08 16:41 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-08 11:53 "&" for array versus "&" for Strings Grein, Christoph
2002-10-08 13:46 ` Preben Randhol
2002-10-08 13:49 ` Preben Randhol
2002-10-08 16:41 ` Robert A Duff [this message]
2002-10-09  9:35   ` Preben Randhol
  -- strict thread matches above, loose matches on Subject: below --
2002-10-10  6:28 Grein, Christoph
2002-10-10  7:15 ` Preben Randhol
2002-10-10  4:35 Grein, Christoph
2002-10-10  6:06 ` Preben Randhol
2002-10-09  9:59 Grein, Christoph
2002-10-09  5:28 Grein, Christoph
2002-10-09 12:43 ` Robert A Duff
2002-10-09 17:38   ` Steven Deller
2002-10-09 19:46     ` Robert A Duff
     [not found] <200210081153.NAA17399@bulgaria.otn.eurocopter.de>
2002-10-08 12:21 ` David C. Hoos, Sr.
2002-10-08 13:56   ` Sergey Koshcheyev
2002-10-08 15:46     ` David C. Hoos
2002-10-08 15:56       ` Preben Randhol
2002-10-08 10:57 Preben Randhol
2002-10-14 16:34 ` Eric G. Miller
2002-10-14 17:54   ` Robert A Duff
replies disabled

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