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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c022fc5445abd13d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!dotsrc.org!news.dotsrc.org!not-for-mail Date: Thu, 03 Nov 2005 18:06:30 +0200 Subject: Re: Discriminated types with default discriminants Newsgroups: comp.lang.ada References: From: "Martin Krischik" Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: User-Agent: Opera M2/8.50 (Win32, build 7700) Organization: SunSITE.dk - Supporting Open source NNTP-Posting-Host: 213.154.204.120 X-Trace: news.sunsite.dk DXC=H08:IKackJZjXN@]UnT6J_YSB=nbEKnk[[>U=@_K4@:US5daR30PdPUV:_8RJBabH];O^i0GOe`^SQ0@8]fPl=F^6eHFFP90ORV4>6B]=RkIgW X-Complaints-To: staff@sunsite.dk Xref: g2news1.google.com comp.lang.ada:6149 Date: 2005-11-03T18:06:30+02:00 List-Id: Am 03.11.2005, 17:50 Uhr, schrieb Maciej Sobczak : > 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