comp.lang.ada
 help / color / mirror / Atom feed
Subject: Re: confusion with string initialization
Date: Sat, 17 Apr 2010 19:42:54 +0200
Date: 2010-04-17T19:42:54+02:00	[thread overview]
Message-ID: <4bc9f31e$0$272$14726298@news.sunsite.dk> (raw)
In-Reply-To: <ZpWdnRumIodDKFTWnZ2dnUVZ_tudnZ2d@giganews.com>

brett wrote:
> I'm trying to learn Ada 2005 with GNAT ( Linux) and are having problems with string initialization using the 
> 
> bs := 20 * " ";  
> 
> construct, which always gives an error 
> 
> "universal integer expected"
> 
> As my syntax is similar to that in Ada 2005 book by Barnes
> (page 594 & 596) I'm a bit confused :-)
> Searching the ARM was of no value either !
> 
> Thanks for any input

Hey Brett,

Here's how the complete example from the excellent John Barnes book 
could look:


with Ada.Strings.Bounded;           use Ada.Strings.Bounded;
with Ada.Strings.Fixed;             use Ada.Strings.Fixed;
with Ada.Strings.Unbounded;         use Ada.Strings.Unbounded;
with Ada.Text_IO;                   use Ada.Text_IO;
with Ada.Text_IO.Bounded_IO;
with Ada.Strings.Unbounded.Text_IO; use Ada.Strings.Unbounded.Text_IO;

procedure String_Test is
    package Bounded_80 is new Generic_Bounded_Length (80);
    use Bounded_80;
    package Bounded_80_IO is new Bounded_IO (Bounded_80);
    use Bounded_80_IO;

    BS : Bounded_String;
    US : Unbounded_String;
    S15 : String (1 .. 15);
begin
    BS := 2 * "Bar";
    Put_Line (BS);

    US := 3 * 'A';
    Put_Line (US);

    US := 2 * US;
    Put_Line (US);

    S15 := 5 * "SOS";
    Put_Line (S15);
end String_Test;


And here's the output you should get when executing the program:

BarBar
AAA
AAAAAA
SOSSOSSOSSOSSOS

-- 
Regards,
Thomas L�cke

Email: tl at ada-dk.org
Web: http:ada-dk.org
IRC nick: ThomasLocke



  parent reply	other threads:[~2010-04-17 17:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-17 13:21 confusion with string initialization brett
2010-04-17 13:06 ` Georg Bauhaus
2010-04-17 17:42 `  [this message]
2010-04-17 19:01 ` J-P. Rosen
2010-04-17 21:30 ` Jeffrey R. Carter
2010-04-18  2:13 ` brett
2010-04-18 13:36   ` Alex Mentis
2010-04-19 14:54   ` Colin Paul Gloster
2010-04-19 14:12     ` J-P. Rosen
2010-04-19 18:20       ` John B. Matthews
2010-04-19 23:18         ` Adam Beneschan
2010-04-20  3:37           ` John B. Matthews
2010-04-27  9:08       ` Jacob Sparre Andersen
2010-04-28 13:26         ` BrianG
2010-04-19 19:48     ` 
2010-04-19 20:05       ` Warren
2010-04-19 20:06       ` Georg Bauhaus
2010-04-21  1:12 ` brett
replies disabled

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