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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5d4ade2fd8fd67c6 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!o18g2000yqm.googlegroups.com!not-for-mail From: Anh Vo Newsgroups: comp.lang.ada Subject: Re: Legit Warnings or not Date: Thu, 21 Jul 2011 11:43:23 -0700 (PDT) Organization: http://groups.google.com Message-ID: <5b1684ab-1b34-4a90-8942-06d10e17d4ed@o18g2000yqm.googlegroups.com> References: <531193e0-3305-4292-9ed8-0176226c1d00@x12g2000yql.googlegroups.com> NNTP-Posting-Host: 149.32.224.35 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1311273923 26378 127.0.0.1 (21 Jul 2011 18:45:23 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 21 Jul 2011 18:45:23 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: o18g2000yqm.googlegroups.com; posting-host=149.32.224.35; posting-account=Qh2kiQoAAADpCLlhT_KTYoGO8dU3n4I6 User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESRCNK X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:21248 Date: 2011-07-21T11:43:23-07:00 List-Id: On Jul 20, 4:16=A0pm, Robert A Duff wrote: > Anh Vo writes: > > > The code segment above triggers a warnings message 'creation of > > "Warned_Person" object may raise Storage_Error' at line 3 as marked. > > However, no warnings is issued at line 8. The difference between them > > is default discriminant. I am using GNAT-GPL-2011. > > There's a confusing rule in Ada: =A0If it has defaults, there can be > unconstrained objects of that type (and also constrained ones). > If it doesn't have defaults, then all objects must be constrained. > > So if you say "X : Warned_Person;", GNAT will allocate space for > billions of characters (not just 10) because you might assign > a bigger one (like "X :=3D (Size =3D> 1_000_000, Name =3D> Something)"). > > > Is this warnings legitimate? If yes, why line 8 is OK. Otherwise, > > should it be a bug? > > It's not a bug. =A0An object of type Warned_Person might need huge amount= s > of memory, so Storage_Error might well be raised. =A0It's illegal to say > "X : Acceptable_Person;", so that one doesn't get a warning. I got it now. Thanks. > If you want unconstrained objects, use a reasonably-small size, like: > > =A0 =A0subtype Name_Length is Natural range 0..1000; > > =A0 =A0type Not_Warned_Person (Size : Name_Length :=3D 0) is > =A0 =A0 =A0 record > =A0 =A0 =A0 =A0 =A0Name : String (1 .. Size); > =A0 =A0 =A0 end record; Good suggestion. Again, thanks. Anh Vo