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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1f0eb93f00b3420e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-09-24 14:27:08 PST Newsgroups: comp.lang.ada Path: bga.com!news.sprintlink.net!howland.reston.ans.net!gatech!newsxfer.itd.umich.edu!zip.eecs.umich.edu!yeshua.marcam.com!MathWorks.Com!noc.near.net!inmet!dsd!bobduff From: bobduff@dsd.camb.inmet.com (Bob Duff) Subject: Re: Rational Compiler Problem ?? Message-ID: Sender: news@inmet.camb.inmet.com Organization: Intermetrics, Inc. References: <35ur1m$9n3@source.asset.com> Date: Sat, 24 Sep 1994 21:19:30 GMT Date: 1994-09-24T21:19:30+00:00 List-Id: In article <35ur1m$9n3@source.asset.com>, Andrew R. McConnell wrote: >Hi folks. Is there _anything_ wrong or non-portable with this code? > >------------------- >with Text_IO; > >procedure Bug_Test is > > type Text_Field ( The_Text_Size : Positive := 1 ) is > record > The_Text : String ( 1 .. The_Text_Size ) := ( others => ' ' ) ; > end record ; > >Size : Positive := 5 ; >My_Text_Field : Text_Field(Size); > >begin > Text_IO.Put_Line("Hello"); >end Bug_Test; >-------------------- The above code should work fine on all implementations. However, whenever you give a default for a discriminant, that means you're allowed to declared uncontrained variables of the type (i.e. variables where the discriminant can change on assignment). It makes sense to warn you about this -- if you don't intent to create unconstrained variables, then you shouldn't give a default; if you do intend to create unconstrained variables, then you had better declare a shorter range for the discriminant, or else you will get Storage_Error, at least on some implementations. Ada is intended, at least in part, for real-time systems, where using the heap without the user's permission is a no-no (user's permission means the user wrote a "new"). So many compilers will allocate unconstrained variables of the above type with the maximum possible size, which in the above case, will raise Storage_Error. Some compilers will allocate such unconstrained variables on the heap, with the current size, and if the size changes, deallocate the old thing and reallocate a new one, and so will not raise S_E unless you actually try to create something big. But counting on this is not portable, and won't work properly in certain real-time situations anyway. >It compiles, links, and runs cleanly in my IBM/AIX environment as well >as in the DEC Ada environment. However, when compiled on the >HP/Rational platform, warning messages(not errors) are generated: > > 104: type Text_Field ( The_Text_Size : Positive := 1 ) is > 105: record >A ---------^ >A:warning: RM Appendix F: storage needed for component exceeds implementation li >mit > 106: The_Text : String ( 1 .. The_Text_Size ) := >A ----------------------------------^ >A:warning: RM Appendix F: unconstrained record component size exceeds limit > 107: ( others => ' ' ) ; > > > >Is this a problem with the Rational compiler? This code _will_ link, >but the executable fails miserably. I don't have access to the >documentation as to known bugs, etc. The warning seems reasonable, but the program should still work. You did *not* create an unconstrained variable, so it should *not* try to allocate a huge amount of storage. >Also, is there any such thing as an "acceptable" warning from an Ada >compiler? (I hope not - how else can I make fun of C-philes? ;-) ) The RM has nothing to say about warnings -- it's entirely up to the compiler. Some compilers "cry wolf" with warnings that can be safely ignored. That's annoying. But the above warning seems like a good one. Just remove the default expression, or else use a smaller range than Positive for the The_Text_Size. As for C, most of the "warnings" you get from a C compiler will be "errors" in an Ada compiler. -- Bob Duff bobduff@inmet.com Oak Tree Software, Inc. Ada 9X Mapping/Revision Team (Intermetrics, Inc.)