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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,903f8471df09a778 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: warning: Storage_Error will be raised at run-time Date: 1997/12/16 Message-ID: #1/1 X-Deja-AN: 298713581 Sender: news@inmet.camb.inmet.com (USENET news) References: <97121608442667@psavax.pwfl.com> X-Nntp-Posting-Host: houdini.camb.inmet.com Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1997-12-16T00:00:00+00:00 List-Id: Marin David Condic, 561.796.8997, M/S 731-96 (condicma@PWFL.COM) wrote: : Tucker Taft writes: : >The purpose of discriminated records is not so much to accomodate individual : >growing objects, but rather to accommodate multiple objects of different : >sizes, which are nevertheless all of the same type. : > : I think that was kind of what I was shooting at: I may need one : object with 5 characters in it and another object with a thousand. : If that means that all objects of the type have to allocate a : thousand bytes, then it seems like you loose any advantage of : having a discriminant - just allocate the string to be a thousand : bytes long from the get-go. The DEC Ada compiler at least gives : the appearance of doing what I'm looking for in this case - at : least it never issued any warnings about Storage_Error. : Is there any way to coerce the compiler into the behavior I want? : (Allocating what I request off of the stack?) All you need to do is specify the value of the discriminant at the point of declaration. It is only if you allow the discriminant to default that the compiler will allocate the maximum possible, since it is only then that you are allowed to change the size of the object as a side-effect of assignment. I presume GNAT is giving you the warning because you specified a default for the discriminant. Just leave out the default, and I suspect the warning will go away. GNAT is reasonably presuming that if you give a default, you might take advantage of it some day. However, if you do use the default, you will get a *very* large object, because the subtype of the discriminant has a huge range. If you do want to take advantage of the default, then you should declare a subtype with a narrower range. GNAT will compute the max size needed and find it tolerable, and thereby not give you the warning. I believe the implementation approach of GNAT, DEC, and our front end are all the same. The only difference is that GNAT gives you a warning when you give a default for a discriminant that has a huge subtype range, while the others give you the bad news when you take advantage of the default (i.e. at an object declaration without an explicit discriminant). The GNAT warning seems pretty "friendly" to me, but you never know with warnings... : Marin David Condic, Senior Computer Engineer Voice: 561.796.8997 : Pratt & Whitney GESP, M/S 731-96, P.O.B. 109600 Fax: 561.796.4669 : West Palm Beach, FL, 33410-9600 Internet: CONDICMA@PWFL.COM -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA