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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news1.google.com!newsread.com!news-xfer.newsread.com!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!bandi.nntp.kabelfoon.nl!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!feeder.xsnews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Discriminated types with default discriminants Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Thu, 3 Nov 2005 18:28:18 +0100 Message-ID: <1gdtkcikbwlt.en1zkjnwfjb8$.dlg@40tude.net> NNTP-Posting-Date: 03 Nov 2005 18:28:06 MET NNTP-Posting-Host: 411f6be2.newsread2.arcor-online.net X-Trace: DXC=`FL6TT8GUn?D9BSA]\F;a On Thu, 03 Nov 2005 16:50:12 +0100, Maciej Sobczak wrote: > 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? > > I can get rid of the second warning by declaring S as: > > S : Discriminated(10); > > Indeed - program runs fine (i.e. it does not raise any exception). > What's the difference? > > I can get rid of the first warning with this: > > subtype MyInt is Integer; > type Discriminated(Size : MyInt := 10) is > -- ... > > What's the difference? No difference, just another GNAT's "feature", GNAT will raise Storage_Error at run-time. What will indeed make difference is this: subtype Expected_Sizes is Natural range 0..1000; type Discriminated (Size : Expected_Sizes := 10) is record Value : String (1..Size); end record; But better is to remove the default value. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de