From: "Grein, Christoph" <christoph.grein@eurocopter.com>
Subject: Re: Discriminated record question
Date: Tue, 7 May 2002 14:45:34 +0200 (MET DST)
Date: 2002-05-07T14:45:34+02:00 [thread overview]
Message-ID: <mailman.1020775682.16866.comp.lang.ada@ada.eu.org> (raw)
> From: Mark.Doherty@uk.thalesgroup.com (Mark Doherty)
>
> Why does the following raise a constraint error on the declaration of
> 'B'.
>
> procedure Test is
> type A_Type (Text_Size : Natural := 0) is
> record
> Text : String (1 .. 0);
> end record;
> A : A_Type;
Text component is always empty here, whichever Text_Size you use, so all objects
have the same (small) size.
>
> type B_Type (Text_Size : Natural := 0) is
> record
> Text : String (1 .. Text_Size);
> end record;
>
> B : B_Type;
I presume, Storage_Error is raised, not Constraint_Error as you claim.
Here Text component depends on Text_Size. You define an unconstrained object, so
the discriminant can vary, therefore the compiler has to allocate the maximum
size, which is Natural'Last - quite big I'd say.
(A different model could be implemented by implicitly allocating on the heap as
much storage as is currently needed. But this model is rarely used - is it
currently used at all by some compiler?)
So the difference is not so subtle...
next reply other threads:[~2002-05-07 12:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-05-07 12:45 Grein, Christoph [this message]
2002-05-07 19:18 ` Discriminated record question Randy Brukardt
2002-05-09 2:52 ` Robert Dewar
2002-05-09 20:29 ` Randy Brukardt
2002-05-08 10:10 ` Mark Doherty
2002-05-09 2:56 ` Robert Dewar
2002-05-15 15:34 ` Mark Doherty
2002-05-15 18:12 ` Jeffrey Carter
-- strict thread matches above, loose matches on Subject: below --
2002-05-16 5:03 Grein, Christoph
2002-05-07 12:17 Mark Doherty
2002-05-10 9:27 ` Emmanuel Briot
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox