comp.lang.ada
 help / color / mirror / Atom feed
From: Preben Randhol <randhol+news@pvv.org>
Subject: "&" for array versus "&" for Strings
Date: Tue, 8 Oct 2002 10:57:59 +0000 (UTC)
Date: 2002-10-08T10:57:59+00:00	[thread overview]
Message-ID: <slrnaq5ehk.5c6.randhol+news@kiuk0152.chembio.ntnu.no> (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



             reply	other threads:[~2002-10-08 10:57 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-08 10:57 Preben Randhol [this message]
2002-10-14 16:34 ` "&" for array versus "&" for Strings Eric G. Miller
2002-10-14 17:54   ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
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
     [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-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
2002-10-09  9:59 Grein, Christoph
2002-10-10  4:35 Grein, Christoph
2002-10-10  6:06 ` Preben Randhol
2002-10-10  6:28 Grein, Christoph
2002-10-10  7:15 ` Preben Randhol
replies disabled

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