From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!cleanfeed2-b.proxad.net!nnrp3-2.free.fr!not-for-mail Subject: Re: Bounded String question Newsgroups: comp.lang.ada References: <7ba56b33-28d4-42d2-8b9b-5ad9f5beab8b@googlegroups.com> <87io597447.fsf@theworld.com> <87egfw7dnm.fsf@theworld.com> From: Xavier Petit Date: Sun, 6 Mar 2016 19:59:46 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.6.0 MIME-Version: 1.0 In-Reply-To: <87egfw7dnm.fsf@theworld.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Message-ID: <56dc7e22$0$19749$426a34cc@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 06 Mar 2016 19:59:46 CET NNTP-Posting-Host: 78.217.21.11 X-Trace: 1457290786 news-4.free.fr 19749 78.217.21.11:44454 X-Complaints-To: abuse@proxad.net Xref: news.eternal-september.org comp.lang.ada:29687 Date: 2016-03-06T19:59:46+01:00 List-Id: 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