From: Xavier Petit <xpetit@becoast.fr>
Subject: Re: Bounded String question
Date: Sun, 6 Mar 2016 19:59:46 +0100
Date: 2016-03-06T19:59:46+01:00 [thread overview]
Message-ID: <56dc7e22$0$19749$426a34cc@news.free.fr> (raw)
In-Reply-To: <87egfw7dnm.fsf@theworld.com>
Le 11/11/2015 16:34, Bob Duff a écrit :
> No, the type is limited, so GNAT will allocate space for Max_Length
> characters, not Natural'Last characters.
>
> - Bob
>
Hello, I have noticed a problem with this technique, and I would like
to know if it is normal or a GNAT problem. With this source code =>
procedure Test_Bounded_String is
package Bounded_String is
type T (Max_Length : Natural := 100) is limited private;
private
type T (Max_Length : Natural := 100) is limited record
Length : Natural := 0;
Chars : String (1 .. Max_Length);
end record;
end Bounded_String;
Test : Bounded_String.T;
begin
null;
end Test_Bounded_String;
$ gnatmake test_bounded_string.adb
gcc-5 -c test_bounded_string.adb
test_bounded_string.adb:12:04: warning: variable "Test" is never read
and never assigned
gnatbind-5 -x test_bounded_string.ali
gnatlink-5 test_bounded_string.ali
$ ./test_bounded_string
raised STORAGE_ERROR : stack overflow or erroneous memory access
But, if the type "T" is publicly fully declared, then all goes well :
package Bounded_String is
type T (Max_Length : Natural := 100) is limited record
Length : Natural := 0;
Chars : String (1 .. Max_Length);
end record;
end Bounded_String;
$ gnatmake --version
GNATMAKE 5.3.1
$ cat /etc/debian_version
stretch/sid
$ apt-cache show gnat-5
Package: gnat-5
Source: gcc-5
Version: 5.3.1-8
$ cat /proc/version
Linux version 4.3.0-1-amd64 (debian-kernel@lists.debian.org) (gcc
version 5.3.1 20160121 (Debian 5.3.1-7) ) #1 SMP Debian 4.3.5-1 (2016-02-06)
The problem also occurs with GNAT 4.9.2 from Debian stable.
Thanks by advance !
--
Xavier Petit
next prev parent reply other threads:[~2016-03-06 18:59 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-10 22:00 Bounded String question Serge Robyns
2015-11-11 0:48 ` Bob Duff
2015-11-11 2:01 ` Jeffrey R. Carter
2015-11-11 15:34 ` Bob Duff
2015-11-11 17:36 ` Jeffrey R. Carter
2015-11-11 19:22 ` Bob Duff
2016-03-06 18:59 ` Xavier Petit [this message]
2016-03-07 23:16 ` Randy Brukardt
2016-03-08 0:08 ` Jeffrey R. Carter
2016-03-09 1:18 ` Randy Brukardt
2015-11-11 10:52 ` Serge Robyns
2015-11-11 13:43 ` Serge Robyns
2015-11-11 14:32 ` brbarkstrom
2015-11-11 16:08 ` Serge Robyns
2015-11-11 17:27 ` Jeffrey R. Carter
2015-11-11 20:06 ` Serge Robyns
2015-11-11 20:23 ` AdaMagica
2015-11-11 20:27 ` AdaMagica
2015-11-11 20:32 ` Serge Robyns
2015-11-11 20:40 ` AdaMagica
2015-11-12 17:31 ` Serge Robyns
2015-11-12 19:10 ` AdaMagica
2015-11-12 21:29 ` Randy Brukardt
2015-11-12 18:03 ` G.B.
2015-11-12 18:13 ` Serge Robyns
2015-11-12 18:14 ` Serge Robyns
2015-11-12 19:37 ` Randy Brukardt
2015-11-11 20:42 ` Jeffrey R. Carter
2015-11-12 16:59 ` Serge Robyns
2015-11-12 18:39 ` Jeffrey R. Carter
2015-11-12 21:19 ` Randy Brukardt
2015-11-12 21:27 ` Randy Brukardt
2015-11-12 22:32 ` Jeffrey R. Carter
2015-11-13 0:07 ` Randy Brukardt
2015-11-13 1:01 ` Jeffrey R. Carter
2015-11-11 15:41 ` Bob 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