comp.lang.ada
 help / color / mirror / Atom feed
From: stt@ada-uts
Subject: Re: variant records
Date: Thu, 6-Nov-86 10:40:00 EST	[thread overview]
Date: Thu Nov  6 10:40:00 1986
Message-ID: <4700082@ada-uts> (raw)
In-Reply-To: 2886@rsch.WISC.EDU


You have fallen into a couple of Ada traps.
First, all objects created by an allocator are constrained,
even if the type has defaults (see LRM 4.8:5 "If the type
of the created object is an array type or a type with
discriminants, the the created object is always constrained.")
Hence, by saying simply "new node" you have created an object
with the default discriminant, and constrained to stay that way.

Secondly, by having a record component whose discriminant depends
on the discriminant of the enclosing record, the component is
constrained by the enclosing discriminant, and the enclosing
discriminant cannot be changed by assigning to just the component.

To solve your problem, you should either remove the discriminant
from the outer record type "node" and declare the xrec component
without a discriminant (hence unconstrained), or maintain separate
node free lists for each distinct discriminant value, and allocate
using "new node(discrim)" where discrim is the discriminant of
the component rec being pushed (this will require that you pass
discrim as a parameter to your "new_node" function).

  parent reply	other threads:[~1986-11-06 15:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1986-10-31  9:08 variant records Dean Luick
1986-11-03 14:17 ` Bev Sobelman
1986-11-05 16:35 ` stuart
1986-11-06 15:40 ` stt [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-09-14  0:00 Variant Records Shawn Barber
1999-09-14  0:00 ` Matthew Heaney
1999-09-14  0:00 ` Mark Lundquist
1999-09-14  0:00 ` David C. Hoos, Sr.
2004-02-15 22:51 Variant records Ganesh Ramasivan
2004-02-16 10:57 ` Preben Randhol
2004-02-16 15:25   ` Ganesh Ramasivan
2004-02-16 15:46     ` Ludovic Brenta
2004-02-16 16:16     ` Preben Randhol
2004-02-17 14:37       ` Ganesh Ramasivan
2004-02-17 15:43         ` Preben Randhol
2004-02-16 16:59   ` Ganesh Ramasivan
2004-02-16 20:14     ` Simon Wright
2004-02-17 14:56       ` Ganesh Ramasivan
2004-02-17 15:31         ` Robert I. Eachus
2004-02-16 23:17 ` tmoran
replies disabled

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