From: "Martin Krischik" <krischik@users.sourceforge.net>
Subject: Re: Discriminated types with default discriminants
Date: Thu, 03 Nov 2005 18:06:30 +0200
Date: 2005-11-03T18:06:30+02:00 [thread overview]
Message-ID: <op.szn9o4foz25lew@super> (raw)
In-Reply-To: dkdbjk$cd8$1@sunnews.cern.ch
Am 03.11.2005, 17:50 Uhr, schrieb Maciej Sobczak <no.spam@no.spam.com>:
> Hi,
>
> Consider this:
>
> procedure Hello is
>
> type Discriminated(Size : Integer := 10) is
> record
> Value : String (1..Size);
> end record;
>
> S : Discriminated;
>
> begin
> null;
> end Hello;
>
>
> Compiler (GNAT) gives me two warnings:
>
> 5. Value : String (1..Size);
> |
> >>> warning: creation of object of this type may raise
> Storage_Error
>
> 8. S : Discriminated;
> |
> >>> warning: Storage_Error will be raised at run-time
>
>
> Moreover, it keeps a promise and indeed the program raises STORAGE_ERROR
> at run-time.
>
> What's happening here? Why the object S is not created with 10 as the
> default discriminant?
Because you might store a larger object later. So - at least GNAT -
allocate as much memory as needed for the larges possible object - thats 2
GB.
Hint 1: unless this is homework: use Bounded_String or Unbounded_String -
don't reinvent the wheel.
Hint 2: try "type MyInt is range 0 .. 1000;" or whatever upper limit is
sensible.
Martin
Links:
http://en.wikibooks.org/wiki/Ada_Programming/Strings
next prev parent reply other threads:[~2005-11-03 16:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-03 15:50 Discriminated types with default discriminants Maciej Sobczak
2005-11-03 16:06 ` Martin Krischik [this message]
2005-11-03 23:10 ` Robert A Duff
2005-11-04 5:01 ` Jeffrey R. Carter
2005-11-03 16:21 ` Ed Falis
2005-11-03 17:28 ` Dmitry A. Kazakov
2005-11-03 18:51 ` Jeffrey R. Carter
2005-11-03 23:08 ` Robert A Duff
2005-11-04 0:08 ` Adam Beneschan
2005-11-29 2:49 ` Randy Brukardt
2005-12-02 18:22 ` Robert A Duff
2005-11-04 9:18 ` Maciej Sobczak
2005-11-04 3:27 ` Brian May
2005-11-04 13:09 ` Stephen Leake
2005-11-04 17:58 ` Martin Krischik
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox