From: brett on
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

---
frmsrcurl: http://compgroups.net/comp.lang.ada/
From: Georg Bauhaus on
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"

It looks like this might actually be related to
something other than your source fragment?

with Ada.Strings.Fixed;
use Ada.Strings.Fixed;

procedure News32 is
bs : String(1 .. 20);
begin
bs := 20 * " ";
bs(20) := bs(1);
end News32;

$ gnatmake -gnatwa -gnatv -gnato news32.adb
gcc-4.3 -c -gnatwa -gnatv -gnato news32.adb

GNAT 4.3.2
Copyright 1992-2007, Free Software Foundation, Inc.

Compiling: news32.adb (source file time stamp: 2010-04-17 13:02:39)
8 lines: No errors
gnatbind -x news32.ali
gnatlink news32.ali
$
From: Thomas Løcke "tl at on
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
From: J-P. Rosen on
brett a �crit :
> 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"
>

presumably, you forgot the with and/or use clauses for the
string package. Therefore the only "*" operator that's visible is the
one between universal integers (i.e. bare numbers).

Remember: you can use something in Ada only if it is made visible by the
appropriate clauses.


--
---------------------------------------------------------
J-P. Rosen (rosen(a)adalog.fr)
Visit Adalog's web site at http://www.adalog.fr
From: Jeffrey R. Carter on
On Apr 17, 6:21 am, brett <u...(a)compgroups.net/> 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"

You don't really give enough information for us to give definite help.
We have no idea what the subtype of Bs is, nor what context clauses
you have.

GNAT is trying to find a function "*" that takes universal_integer (or
a type that it can be implicitly converted to) for its 1st operand,
and a string type for its right operand. Apparently no such function
is visible, and it's telling you what is needed to match a visible
function "*" that it did find. Clearly that msg isn't useful for you.

There are such functions defined in the various Ada.Strings.* pkgs.
Perhaps you have mentioned one of those in a context clause, but have
not made the function directly visible through a renaming, a use
clause, or a use type clause. You could either add such direct
visibility, or use the function's full name:

Bs := Ada.Strings.Fixed."*" (20, " ");

for example.