comp.lang.ada
 help / color / mirror / Atom feed
* Re: "&" for array versus "&" for Strings
@ 2002-10-10  6:28 Grein, Christoph
  2002-10-10  7:15 ` Preben Randhol
  0 siblings, 1 reply; 21+ messages in thread
From: Grein, Christoph @ 2002-10-10  6:28 UTC (permalink / raw)


> > Has the OP reported this to ACT? I think he was using Gnat.
> 
> No I haven't. I don't know how to do it. Does anybody have a link to a
> document on reporting bugs? But if the bug I see has been changed from
> Gnat 3.14p to 3.16w then I think that one need to report the new bug in
> Gnat 3.16w?

The address to report bugs is
  report@gnat.com
but do not expect reactions if you're not a supported user.

But since even in 3.16w it's possibley not OK, send it in anyway. In the program 
below, only the qualified expressions and array aggregates compile.

procedure Preben is

  type String_Array is array (1 .. 2) of String (1 .. 3);

  procedure P (X: String_Array) is
  begin
    null;
  end P;

  S1: String_Array := "Ada" & "C++";                    -- not OK
  S2: String_Array := String'("Ada") & String'("C++");  -- OK
  S3: String_Array := ("Ada", "C++");                   -- OK

begin

  P ("Ada" & "C++");                    -- not OK
  P (String'("Ada") & String'("C++"));  -- OK
  P (("Ada", "C++"));                   -- OK

end Preben;



^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: "&" for array versus "&" for Strings
@ 2002-10-10  4:35 Grein, Christoph
  2002-10-10  6:06 ` Preben Randhol
  0 siblings, 1 reply; 21+ messages in thread
From: Grein, Christoph @ 2002-10-10  4:35 UTC (permalink / raw)


> There is no aggregate in this example.


Oops, you'r right, I thought a string literal was a short form of a character 
array aggregate. But the RM treats is separately and allows to replace array 
aggregates by string literals in certain circumstances.

So I think the unqualified Print_Names ("Ada   " & "Babbel"); should resolve OK. 
so Gnat is in error here.

Has the OP reported this to ACT? I think he was using Gnat.



^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: "&" for array versus "&" for Strings
@ 2002-10-09  9:59 Grein, Christoph
  0 siblings, 0 replies; 21+ messages in thread
From: Grein, Christoph @ 2002-10-09  9:59 UTC (permalink / raw)


If you are interested in problems with unexpected ambiguities of this sort, see 
my paper

http://home.T-Online.de/home/Christ-Usch.Grein/AdaMagica/Invitation.html




^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: "&" for array versus "&" for Strings
@ 2002-10-09  5:28 Grein, Christoph
  2002-10-09 12:43 ` Robert A Duff
  0 siblings, 1 reply; 21+ messages in thread
From: Grein, Christoph @ 2002-10-09  5:28 UTC (permalink / raw)


procedure Array_Test is

  type Name_Array is array (Positive range <>) of String (1..6);

  procedure Print_Names (Names : Name_Array) is separate;

begin

  Print_Names ("Ada   " & "Babbel");
  Print_Names (string'("Ada   ") & string'("Babbel"));

end Array_Test;

> 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.

I think only the first statement is ambiguous since the compiler is not allowed 
to lookk inside the aggregate to see what is is, a string or an array of 
strings.

With the second statment, it's clear the aggregates are strings, so it can 
resolve the "&" operator to the correct one returning Name_Array. The one 
returning String is out because Print_Names does not accept String.



^ permalink raw reply	[flat|nested] 21+ messages in thread
[parent not found: <200210081153.NAA17399@bulgaria.otn.eurocopter.de>]
* Re: "&" for array versus "&" for Strings
@ 2002-10-08 11:53 Grein, Christoph
  2002-10-08 13:46 ` Preben Randhol
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Grein, Christoph @ 2002-10-08 11:53 UTC (permalink / raw)


> ------------------------------------------------------------------
> 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.

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.



^ permalink raw reply	[flat|nested] 21+ messages in thread
* "&" for array versus "&" for Strings
@ 2002-10-08 10:57 Preben Randhol
  2002-10-14 16:34 ` Eric G. Miller
  0 siblings, 1 reply; 21+ messages in thread
From: Preben Randhol @ 2002-10-08 10:57 UTC (permalink / raw)


According to the ARM 4.5.3:

  3. The concatenation operators & are predefined for every nonlimited,
     one-dimensional array type T with component type C. They have the
     following specifications:

  4.      function "&"(Left : T; Right : T) return T
          function "&"(Left : T; Right : C) return T
          function "&"(Left : C; Right : T) return T
          function "&"(Left : C; Right : C) return T

If I use this in this way:

------------------------------------------------------------------
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.

If I do :

Print_Names ("Ada   " & "Babbel" & "Odin  ");

gnatmake array_test.adb 
gnatgcc -c array_test.adb
array_test.adb:15:26: ambiguous operand for concatenation
array_test.adb:15:26: possible interpretation at line 4
array_test.adb:15:26: possible interpretation in package Standard
gnatmake: "array_test.adb" compilation error

which is expected.

and 

Print_Names ("Ada   Babbel");

gnatmake array_test.adb 
gnatgcc -c array_test.adb
array_test.adb:15:17: expected type "Name_Array" defined at line 4
array_test.adb:15:17: found a string type
gnatmake: "array_test.adb" compilation error

which is also expected.


-- 
Ada95 is good for you.
http://libre.act-europe.fr/Software_Matters/02-C_pitfalls.pdf



^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2002-10-14 17:54 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-10  6:28 "&" for array versus "&" for Strings Grein, Christoph
2002-10-10  7:15 ` Preben Randhol
  -- strict thread matches above, loose matches on Subject: below --
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 11:53 Grein, Christoph
2002-10-08 13:46 ` Preben Randhol
2002-10-08 13:49 ` Preben Randhol
2002-10-08 16:41 ` Robert A Duff
2002-10-09  9:35   ` 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

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