From: "Beard, Frank" <beardf@spawar.navy.mil>
To: "'comp.lang.ada@ada.eu.org'" <comp.lang.ada@ada.eu.org>
Subject: RE: Pascal's: Variant Record or C's union
Date: Fri, 6 Apr 2001 17:59:29 -0400
Date: 2001-04-06T17:59:29-04:00 [thread overview]
Message-ID: <mailman.986594489.3634.comp.lang.ada@ada.eu.org> (raw)
It's very similar to Pascal.
type Type_Of_Goods is (LIQUID, TEXTILE);
type TYPE_GOODS (GOODS_TYPE : Type_Of_Goods) is
record
ITEM_NAME : string(1..6);
case GOODS_TYPE is
when LIQUID =>
LITRE : float;
VOLUME_PCT : float;
when TEXTILE =>
LENGTH : float;
WIDTH : float;
end case;
end record;
Frank
-----Original Message-----
From: Frank [mailto:franjoe@frisurf.no]
Sent: Friday, April 06, 2001 5:48 PM
To: comp.lang.ada@ada.eu.org
Subject: Pascal's: Variant Record or C's union
Hi!
How do I create a record in Ada, that behaves as the variant record in
Pascal or similar to the union in C?
It seems to me that the expression "variant" in Ada is used on how you
define?/declare? :-) types based on a "type with many possible
apperances":-).
Something like:
type TYPE_GOODS is
record
ITEM_NAME : string(1..6);
GOODS_TYPE : integer;
case GOODS_TYPE <--------???
when LIQUID: <---------???
LITRE : float;
VOLUME_PCT : float;
when TEXTILE:
LENGTH : float;
WIDTH : float;
end case;
end record;
A : TYPE_GOODS;
..
..
A.ITEM_NAME := 'COGNAC';
A.GOODS_TYPE := LIQUID;
A.LITRE := 0.7;
A.VOLUME_PCT := 45;
A.ITEM_NAME := 'RED ';
A.GOODS_TYPE := TEXTILE;
A.LENGTH := 10.0;
A.WIDTH := 0.6;
Frank
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada
next reply other threads:[~2001-04-06 21:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-04-06 21:59 Beard, Frank [this message]
-- strict thread matches above, loose matches on Subject: below --
2001-04-06 21:48 Pascal's: Variant Record or C's union Frank
2001-04-07 3:29 ` DuckE
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox