comp.lang.ada
 help / color / mirror / Atom feed
* Re: Binding a type to a union.
@ 1999-11-23  0:00 Tom_Hargraves
  1999-11-23  0:00 ` Robert Dewar
  1999-11-23  0:00 ` Matthew Heaney
  0 siblings, 2 replies; 25+ messages in thread
From: Tom_Hargraves @ 1999-11-23  0:00 UTC (permalink / raw)
  To: comp.lang.ada


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









^ permalink raw reply	[flat|nested] 25+ messages in thread
* RE: Binding a type to a union.
@ 1999-11-26  0:00 Robert C. Leif, Ph.D.
  1999-11-28  0:00 ` Robert Dewar
  0 siblings, 1 reply; 25+ messages in thread
From: Robert C. Leif, Ph.D. @ 1999-11-26  0:00 UTC (permalink / raw)
  To: comp.lang.ada

From : Bob Leif
To: Robert Dewar et al.

I am gratified that "the extended Ada language technology agreed on by the
ARA technical committee, and has since been discussed by the ARG
as a possible semi-standard extension."

Finally, Ada has some flexibility and adaptability! I hope that 1) the ARA
and ARG can define a process for extending Ada and a better term than "a
possible semi-standard extension." 2) That these semi-standard extensions
keep being created as required with or without a formal process. and 3) An
informal process, at least initially, be set up where we the users can make
suggestions for these "semi-standard extensions."

I like the term provisional extensions. You can even follow the present
commercial software terminology. We could have alpha and beta levels. When
an extension is accepted by ISO, it becomes gold.

-----Original Message-----
From: Robert Dewar [mailto:robert_dewar@my-deja.com]
Sent: Wednesday, November 24, 1999 9:21 PM
To: comp.lang.ada@ada.eu.org
Subject: Re: Binding a type to a union.


In article <81gtd5$rfb$1@nnrp1.deja.com>,
  Ted Dennison <dennison@telepath.com> wrote:
> Perhaps that's because compilers ignore pragmas they don't
recognize.
> Just for fun, try putting a "pragma Foo_Bar;" in one of your
source
> files and compile it with Gnat. The worst you'll see is a:
>    warning: unrecognized pragma "Foo_Bar --
> T.E.D.

Well I assume this is a joke, but I did not see a smiley. Of
COURSE it is the case that if you use Unchecked_Union to
interface to a C union, and it was not implemented, then your
program wouldn't work.

And if indeed the above was intended to be serious, then please
note that a small amount of research would have shown you that
most Ada 95 compilers implement this pragma. It was one of the
first bits of extended Ada language technology agreed on by the
ARA technical committee, and has since been discussed by the ARG
as a possible semi-standard extension.


Sent via Deja.com http://www.deja.com/
Before you buy.








^ permalink raw reply	[flat|nested] 25+ messages in thread
* Binding a type to a union.
@ 1999-11-23  0:00 Aidan Skinner
  1999-11-22  0:00 ` David Botton
  0 siblings, 1 reply; 25+ messages in thread
From: Aidan Skinner @ 1999-11-23  0:00 UTC (permalink / raw)


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
-- 
"I say we just bury him and eat dessert"
http://www.skinner.demon.co.uk/aidan/
OpenPGP Key Fingerprint: 9858 33E6 C755 7D34 B5C5  316D 9274 1343 FBE6 99D9




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

end of thread, other threads:[~1999-12-01  0:00 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-11-23  0:00 Binding a type to a union Tom_Hargraves
1999-11-23  0:00 ` Robert Dewar
1999-11-23  0:00 ` Matthew Heaney
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-23  0:00   ` David Botton
1999-11-24  0:00     ` Ted Dennison
1999-11-25  0:00       ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
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
1999-11-23  0:00 Aidan Skinner
1999-11-22  0:00 ` David Botton

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