comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: warning: Storage_Error will be raised at run-time
Date: 1997/12/16
Date: 1997-12-16T00:00:00+00:00	[thread overview]
Message-ID: <ELAFKo.8wH.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: 97121608442667@psavax.pwfl.com


Marin David Condic, 561.796.8997, M/S 731-96 (condicma@PWFL.COM) wrote:

: Tucker Taft <stt@HOUDINI.CAMB.INMET.COM> 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




  reply	other threads:[~1997-12-16  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-16  0:00 warning: Storage_Error will be raised at run-time Marin David Condic, 561.796.8997, M/S 731-96
1997-12-16  0:00 ` Tucker Taft [this message]
1997-12-16  0:00 ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1997-12-15  0:00 Marin David Condic, 561.796.8997, M/S 731-96
1997-12-15  0:00 ` Robert Dewar
1997-12-15  0:00 ` Tucker Taft
replies disabled

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