Article View: net.lang.ada
Article #1036variant records
From: Dean Luick
Date: Fri, 31 Oct 1986 09:08
Date: Fri, 31 Oct 1986 09:08
70 lines
2267 bytes
2267 bytes
I am trying to write a stack package using a variant record in the main
record type and I am having great difficulty. My problem is the following,
if I have the following definition:
type enum is (A, B, C, D);
type rec(kind : enum := A) is
record
case kind is
when A | B => -- the actual values don't matter
null;
when C | D =>
foo : integer;
end record;
type node(xkind : enum := A);
type node_ptr is access node;
type node(xkind : enum := A) is
record
next : node_ptr;
xrec : rec(xkind);
end record;
stack : node_ptr := NULL;
extra_nodes : node_ptr := NULL;
-- and I have the following later definiions:
procedure push(r : rec) is
temp : node_ptr;
begin
temp := new_node;
temp.xrec := r; -- position 'Z'
temp.next := stack;
stack := temp;
end push;
function new_node return node_ptr is
temp : node_ptr;
begin
temp := extra_nodes;
if temp = NULL then
temp := new node;
else
extra_nodes := extra_nodes.next;
end if;
return temp;
end new_node;
Suppose I create a rec of say, B, and try to push it. At postion 'Z'
a constraint error is raised because of the different variant types ( in
the first case, temp's discriminant is A ). Is there any way around this?
I was led to believe that I cound change the variant part of a type by
assigning it a whole aggregate (is that the right word?) say, like
case r.kind is
. . .
when B =>
temp.xrec := rec'(kind => B)
. . .
Well, I tried that at position 'Z' and it failed. I have run out of ideas.
Any help would be greatly appreciated.
dean
--
Dean Luick
uucp: ...!{allegra,harvard,ihnp4,seismo,topaz}!uwvax!dream!dean
arpa: dean@dream.wisc.edu
Technical Details
Message-ID:
<2886@rsch.WISC.EDU>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!uwvax!deanShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!uwvax!dean From: dean@rsch.WISC.EDU (Dean Luick) Newsgroups: net.lang.ada Subject: variant records Message-ID: <2886@rsch.WISC.EDU> Date: Fri, 31-Oct-86 04:08:54 EST Article-I.D.: rsch.2886 Posted: Fri Oct 31 04:08:54 1986 Date-Received: Fri, 31-Oct-86 14:45:27 EST Organization: the Fell Lines: 70