From: Joel VanLaven <jvl@ocsystems.com>
Subject: Re: private type discriminants ignored?
Date: 1998/04/24
Date: 1998-04-24T00:00:00+00:00 [thread overview]
Message-ID: <3540cb0b.0@news4.his.com> (raw)
In-Reply-To: rz84szje1ol.fsf@cs.williams.edu
Jay Sachs <sachs@cs.williams.edu> wrote:
[message trimmed for content]
: type Stack(Size : Integer := 100) is record
: Top : Natural := 0;
: Rep : stackrep(1..Size);
: end record;
: I get warnings (from gnat 3.10) saying that I may get a storage_error
: by creating a variable of type stack. I do in fact get such an error
: if I declare
: s : Stacks4.Stack;
: However, supplying the initialization as in
: s2 : Stacks4.Stack(75);
: with no error. What is the reason that the default initialization
: seems to be ignored in the discriminant for the private type?
Default initializations of the type you are using have a very special
meaning in Ada. They indicate that the constraint can be changed. Objects
declared like s are sometimes referred to as "mutable" meaning that one can
assign to them a value with a constraint other than 100. Essentially,
there are three ways objects get their constriant:
explicitly (forever constained to that value like 75 above)
by initialization (forever constained like a : string := "abcd" will
always have length 4)
by default (mutable, can be changed, un-constrained like s above)
Many (most, all?) compilers implement this by allocating (I'm using that
term loosely) the maximum possible space needed to represent an object of
the type with any constraint. So, s is of size on the order of magnitude
of integer'last. Not good. If size was of some type that ranged from
1 to 200 GNAT would likely make s of size on the order of 200 and
everything would be fine.
I don't think you really want mutable objects here. It can be useful
but is one of the trickier and fancier features in Ada, and I don't think
it is what you are looking for.
-- Joel VanLaven
-- (I just happen to work for OC Systems)
next prev parent reply other threads:[~1998-04-24 0:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Es7569.4n2@world.std.com>
1998-04-24 0:00 ` private type discriminants ignored? Jay Sachs
1998-04-24 0:00 ` Joel VanLaven [this message]
[not found] ` <Es3A4J.Ion@world.std.com>
1998-04-28 0:00 ` Samuel T. Harris
1998-04-28 0:00 ` Patrick D. Rogers
1998-04-28 0:00 ` Samuel T. Harris
1998-04-30 0:00 ` Anonymous
[not found] ` <6ib6t4$63f$1@goanna.cs.rmit.edu.au>
1998-05-06 0:00 ` Robert I. Eachus
1998-05-01 0:00 ` Samuel T. Harris
[not found] <matthew_heaney-ya023680003004981720560001@news.ni.net>
1998-05-01 0:00 ` Anonymous
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox