comp.lang.ada
 help / color / mirror / Atom feed
* RE: Pascal's: Variant Record or C's union
@ 2001-04-06 21:59 Beard, Frank
  0 siblings, 0 replies; 3+ messages in thread
From: Beard, Frank @ 2001-04-06 21:59 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

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




^ permalink raw reply	[flat|nested] 3+ messages in thread
* Pascal's: Variant Record or C's union
@ 2001-04-06 21:48 Frank
  2001-04-07  3:29 ` DuckE
  0 siblings, 1 reply; 3+ messages in thread
From: Frank @ 2001-04-06 21:48 UTC (permalink / 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





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-04-07  3:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-06 21:59 Pascal's: Variant Record or C's union Beard, Frank
  -- strict thread matches above, loose matches on Subject: below --
2001-04-06 21:48 Frank
2001-04-07  3:29 ` DuckE

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