From: Emmanuel Briot <briot@act-europe.fr>
Subject: Re: Discriminated record question
Date: 10 May 2002 11:27:32 +0200
Date: 2002-05-10T11:27:32+02:00 [thread overview]
Message-ID: <m34rhgl5dn.fsf@lyon.act-europe.fr> (raw)
In-Reply-To: 2d87db3f.0205070417.7a50667b@posting.google.com
Mark.Doherty@uk.thalesgroup.com (Mark Doherty) writes:
> 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;
>
> type B_Type (Text_Size : Natural := 0) is
> record
> Text : String (1 .. Text_Size);
> end record;
>
> B : B_Type;
>
> begin
> null;
> end Test;
Because when you specify a default value for the discriminant, the compiler
must allocate the maximum possible size (in that case Natural'Last), so you are
trying to declare a huge variable, which raises CE. I thought it would have
raised Storage_Error, but it might be compiler-dependent
Compiling the code above with GNAT gives a proper warning
gcc -c t8.adb
t8.adb:10:33: warning: creation of object of this type may raise Storage_Error
t8.adb:13:05: warning: Storage_Error will be raised at run-time
gnatbind -x t8.ali
gnatlink t8.ali
next prev parent reply other threads:[~2002-05-10 9:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-05-07 12:17 Discriminated record question Mark Doherty
2002-05-10 9:27 ` Emmanuel Briot [this message]
-- strict thread matches above, loose matches on Subject: below --
2002-05-07 12:45 Grein, Christoph
2002-05-07 19:18 ` 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
2002-05-16 5:03 Grein, Christoph
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox