comp.lang.ada
 help / color / mirror / Atom feed
* Unchecked_Union
@ 1996-02-24  0:00 Robert Dewar
  1996-02-27  0:00 ` Unchecked_Union Arthur Evans Jr
  0 siblings, 1 reply; 2+ messages in thread
From: Robert Dewar @ 1996-02-24  0:00 UTC (permalink / raw)


The following is a description of pragma Unchecked_Union as we are
implementing it in GNAT. This description is compatible with the
current Intermetrics usage in their binding generator tool.

Comments welcome -- to CLA, since I think this is of general interest

Note that we intend that other compilers than GNAT will implement this
pragma.

   --  pragma Unchecked_Union (first_subtype_LOCAL_NAME)
   --    This pragma is implementation (GNAT) defined. It is used to declare
   --    that the named type should be equivalent to a C union type, and is
   --    intended only for use in interfacing with C code that uses union
   --    types. In Ada terms, the named type must obey the following rules:

   --       It is a non-tagged non-limited record type
   --       It has a single discrete discriminant with a default value
   --       Pragma Suppress (Discriminant_Check) applies implicitly
   --       The component list consists of a single variant part
   --       The default convention is C
   --       Each variant has a component list with a single component
   --       No nested variants are allowed
   --       No component can have an explicit default value
   --       No component can have a non-static constraint
   --
   --    In addition, given a type that meets the above requirements, the
   --    following restrictions apply to its use throughout the program:
   --
   --       The discriminant name can be mentioned only in an aggregate
   --       No subtypes may be created of this type
   --       The type may not be constrained by giving a discriminant value
   --       An unchecked union type cannot be passed as the actual for a
   --        generic formal with a discriminant.

   --    Also, equality and inequality operations on unchecked_unions are not
   --    available, since there is no discriminant to compare, and in general
   --    the compiler does not even know how many bits to compare. It is
   --    implementation dependent whether this is detected at compile time
   --    as an illegality, or whether it is undetected and considered to be
   --    an erroneous construct. In GNAT, a direct comparison is illegal,
   --    but GNAT does not attempt to catch the composite case (where two
   --    composites are compared that contain an unchecked union component),
   --    so such comparisons are simply considered erroneous.
   --
   --    The layout of the resulting type corresponds exactly to a C union,
   --    where each branch of the union corresponds to a single variant in
   --    the Ada record. The semantics of the Ada program is not changed in
   --    any way by the pragma, i.e. provided the above restrictions are
   --    followed, and no erroneous incorrect references to fields or
   --    erroneous comparisons occur, the semantics is exactly as described
   --    by the Ada reference manual.





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

* Re: Unchecked_Union
  1996-02-24  0:00 Unchecked_Union Robert Dewar
@ 1996-02-27  0:00 ` Arthur Evans Jr
  0 siblings, 0 replies; 2+ messages in thread
From: Arthur Evans Jr @ 1996-02-27  0:00 UTC (permalink / raw)


In article <dewar.825178652@schonberg>, dewar@cs.nyu.edu (Robert Dewar) wrote:

> The following is a description of pragma Unchecked_Union as we are
> implementing it in GNAT. This description is compatible with the
> current Intermetrics usage in their binding generator tool.

This looks most interesting.  Two small comments:

>  Also, equality and inequality operations on unchecked_unions are not
>  available, since there is no discriminant to compare, and in general
>  the compiler does not even know how many bits to compare. It is
>  implementation dependent whether this is detected at compile time
>  as an illegality, or whether it is undetected and considered to be
>  an erroneous construct. In GNAT, a direct comparison is illegal,
>  but GNAT does not attempt to catch the composite case (where two
>  composites are compared that contain an unchecked union component),
>  so such comparisons are simply considered erroneous.

My quibble is with the last quoted word.  I think you could safely say
that this is a bounded error, since the only effect is that the
comparison will give the wrong answer.

>  The layout of the resulting type corresponds exactly to a C union,
>  ...

I wonder whether or not that is a well-defined statement.  That is, is
the layout a a C union specified anywhere, even for a specific C
implementation?  (Maybe this comment is off the wall -- I'm not much of
a C programmer.)

Art Evans

Arthur Evans Jr, PhD        Phone: 412-963-0839
Ada Consulting              FAX:   412-963-0927
461 Fairview Road
Pittsburgh PA  15238-1933
evans@evans.pgh.pa.us




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

end of thread, other threads:[~1996-02-27  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-02-24  0:00 Unchecked_Union Robert Dewar
1996-02-27  0:00 ` Unchecked_Union Arthur Evans Jr

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