comp.lang.ada
 help / color / mirror / Atom feed
From: "Frank" <franjoe@frisurf.no>
Subject: Pascal's: Variant Record or C's union
Date: Fri, 6 Apr 2001 23:48:26 +0200
Date: 2001-04-06T23:48:26+02:00	[thread overview]
Message-ID: <UQqz6.6485$NR.552875@news3.oke.nextra.no> (raw)

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





             reply	other threads:[~2001-04-06 21:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-04-06 21:48 Frank [this message]
2001-04-07  3:29 ` Pascal's: Variant Record or C's union DuckE
  -- strict thread matches above, loose matches on Subject: below --
2001-04-06 21:59 Beard, Frank
replies disabled

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