From: Tom_Hargraves@Raytheon.com
To: comp.lang.ada@ada.eu.org
Subject: Re: Binding a type to a union.
Date: 1999/11/23
Date: 1999-11-23T17:43:37+00:00 [thread overview]
Message-ID: <OF1AE825B1.88FF8CF8-ON88256832.005C894B@ray.ca> (raw)
Thanks for the example of pragma Unchecked_Union in your reply. I have learnt
another pragma today :-)
However, wouldn't its use be restricted to when the type was to be used in a
'C' language interface call?
The pragma comes with a long list of restrictions which perhaps, generally,
would be undesirable.
Yours curiously,
Tom H.
"David Botton" <David@Botton.com> on 11/22/99 07:55:33 PM
Please respond to comp.lang.ada@ada.eu.org
From:"David Botton" <David@Botton.com> on 11/22/99 07:55 PM
To: comp.lang.ada@ada.eu.org
cc: (bcc: Tom Hargraves/RMD/Raytheon/CA)
Subject: Re: Binding a type to a union.
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
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/cgi-bin/mailman/listinfo/comp.lang.ada
next reply other threads:[~1999-11-23 0:00 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-11-23 0:00 Tom_Hargraves [this message]
1999-11-23 0:00 ` Binding a type to a union 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
-- strict thread matches above, loose matches on Subject: below --
1999-11-23 0:00 Aidan Skinner
1999-11-22 0:00 ` David Botton
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