comp.lang.ada
 help / color / mirror / Atom feed
From: "David Botton" <David@Botton.com>
Subject: Re: Binding a type to a union.
Date: 1999/11/22
Date: 1999-11-23T03:55:48+00:00	[thread overview]
Message-ID: <81d384$1g8o$1@news.gate.net> (raw)
In-Reply-To: slrn83jvkm.1mn.aidan@skinner.demon.co.uk

You would do the following:

type foo_struct is
   record
      x : C.Int;
   end record;

type bar_struct is
   record
      x : C.char;
      y : some_enum_type;
   end record;

subtype Union_1_Range is Positive range 1..2;

type Union_1 (Which : Union_1_Range) is
   record
      case Which is
         when 1 =>
            foo : foo_struct;
         when 2 =>
            bar : bar_struct;
   end record;
pragma Unchecked_Union(Union_1);

type foo_type is
   record
     foo_bar : Union_1;
    end record;


Then you can access using:

my : foo_type;

my.foo_bar.foo.x := 1;

etc.

David Botton


Aidan Skinner wrote in message ...
>Can anybody tell me the correct way to give an Ada representation of a
>C union contained in a structure?
>
>Eg given a declaration in C of:
>
>struct foo
> {
>
>   union
>   {
>     struct
>     {
>       int x;
>     } foo
>
>     struct
>     {
>       char x;
>       some_enum_type y;
>     } bar
>
>   } foo_bar
> }
>
>What's the correct way of doing this given that x needs to be
>public?
>
>- Aidan







  reply	other threads:[~1999-11-22  0:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-11-23  0:00 Binding a type to a union Aidan Skinner
1999-11-22  0:00 ` David Botton [this message]
  -- strict thread matches above, loose matches on Subject: below --
1999-11-23  0:00 Tom_Hargraves
1999-11-23  0:00 ` Robert Dewar
1999-11-23  0:00 ` Matthew Heaney
1999-11-23  0:00   ` David Botton
1999-11-24  0:00     ` Ted Dennison
1999-11-25  0:00       ` Robert Dewar
1999-11-23  0:00   ` Robert Dewar
1999-11-24  0:00     ` Larry Kilgallen
1999-11-23  0:00       ` Tom Hargraves
1999-11-24  0:00         ` tmoran
1999-11-25  0:00         ` Robert Dewar
1999-11-25  0:00       ` Robert Dewar
1999-11-25  0:00         ` Larry Kilgallen
1999-11-25  0:00           ` Ed Falis
1999-11-25  0:00             ` Larry Kilgallen
1999-11-25  0:00               ` Robert Dewar
1999-11-29  0:00         ` Ted Dennison
1999-11-24  0:00     ` Aidan Skinner
1999-11-26  0:00 Robert C. Leif, Ph.D.
1999-11-28  0:00 ` Robert Dewar
1999-11-28  0:00   ` Vladimir Olensky
1999-12-01  0:00     ` Robert Dewar
1999-12-01  0:00     ` Robert Dewar
replies disabled

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