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!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: CONSTRAINT ERROR? access check failed Date: Thu, 1 Mar 2018 18:56:32 +0100 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: <39fc7bbf-77e8-4342-9af7-68cb5e9acb8a@googlegroups.com> <1e744a67-b2bf-437c-b503-8bd4c13da655@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 1 Mar 2018 17:56:32 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="942e0510277745b3345d34ee262393ec"; logging-data="1206"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WeTcRuU18uxhimz9Y0PPTZxL5puiIqzc=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:ICFQZiDLbRMleJUsQStiLSBlFF0= Xref: reader02.eternal-september.org comp.lang.ada:50758 Date: 2018-03-01T18:56:32+01:00 List-Id: On 03/01/2018 03:38 PM, Mehdi Saada wrote: > Work finished ! Thank you. > But I would like to know why I get a warning at compile time with > type Link (Num : LINE_NUMBER := 0; Length : NATURAL := 0) is > record > NEXT : access LINK := null; > Line : String (1 .. Length) := (1..Length => ' '); > end record; > As if it could cause a stack overflow (was written as is). Yet I don't get at each compilation, surprisingly. Because you have defaults for your discriminants, you can declare V : Link; V is then unconstrained. You can change its discriminants through whole-record assignment: V := (Num => 23, Length => 42, Next => null, Line => (1 .. 42 => 'S') ); The way GNAT handles this is to allocate space for the largest variant, and only use the part for the current discriminant. Apparently GNAT doesn't use a stack large enough to handle a string of length Integer'Last. Why is Num a discriminant? There's no reason for a discriminant that isn't used in the record definition. -- Jeff Carter "Facts do not cease to exist because they are ignored." Aldous Huxley 134