comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@dsd.camb.inmet.com (Bob Duff)
Subject: Re: Rational Compiler Problem ??
Date: Sat, 24 Sep 1994 21:19:30 GMT
Date: 1994-09-24T21:19:30+00:00	[thread overview]
Message-ID: <CwnKKI.Jvo@inmet.camb.inmet.com> (raw)
In-Reply-To: 35ur1m$9n3@source.asset.com

In article <35ur1m$9n3@source.asset.com>,
Andrew R. McConnell <mcconnel@source.asset.com> 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.)



  parent reply	other threads:[~1994-09-24 21:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-09-23 15:08 Rational Compiler Problem ?? Andrew R. McConnell
1994-09-23 16:33 ` Kent Mitchell
1994-09-24 21:19 ` Bob Duff [this message]
1994-09-26 12:50 ` Alan D Zimmerman, Loral RSA
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox