comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: CONSTRAINT ERROR? access check failed
Date: Thu, 1 Mar 2018 18:56:32 +0100
Date: 2018-03-01T18:56:32+01:00	[thread overview]
Message-ID: <p79esg$15m$1@dont-email.me> (raw)
In-Reply-To: <ad65ac6f-a479-46bd-9f4c-a1c87ed938b3@googlegroups.com>

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

  parent reply	other threads:[~2018-03-01 17:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-01  0:27 CONSTRAINT ERROR? access check failed Mehdi Saada
2018-03-01  8:07 ` Niklas Holsti
2018-03-01 12:44   ` Mehdi Saada
2018-03-01 13:45     ` Björn Lundin
2018-03-01 14:06   ` Mehdi Saada
2018-03-01 14:31     ` Mehdi Saada
2018-03-01 14:38     ` Mehdi Saada
2018-03-01 15:53       ` Anh Vo
2018-03-01 17:24         ` Mehdi Saada
2018-03-01 18:34           ` Anh Vo
2018-03-01 17:26       ` Simon Wright
2018-03-01 17:47         ` Mehdi Saada
2018-03-01 17:56       ` Jeffrey R. Carter [this message]
2018-03-01  8:30 ` Simon Wright
2018-03-01 12:14   ` Mehdi Saada
2018-03-01 13:27     ` Simon Wright
2018-03-01 13:44       ` Mehdi Saada
replies disabled

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