comp.lang.ada
 help / color / mirror / Atom feed
* GNAT Unchecked_Union and multiple components
@ 2005-04-18 14:58 Brian
  2005-04-20 21:03 ` Randy Brukardt
  0 siblings, 1 reply; 2+ messages in thread
From: Brian @ 2005-04-18 14:58 UTC (permalink / raw)


Hi,

I've started to use GNAT 3.15p and noticed it handles the pragma
Unchecked_Union differently from other compilers.  According to the
GNAT Reference Manual "Each variant has a component list with a single
component.", if you violate this rule the compiler will generate the
error "Unchecked_Union variant can have only one component".  Other
compilers allow multiple components per variant.  Is there a GNAT
compiler switch I can use to loosen this restriction?  My current
workaround is to create a new record type containing the multiple
components and use it as the type for one of the variants (see code
snippet below).  Thanks.

Regards,
Brian


<snip>

type Msg_Type is (Msg_A, Msg_B);

-- This is what I want as my variant record type definition.

type Data_Type1(Msg : Msg_Type := Msg_A) is
   record
      case Msg is
         when Msg_A =>
            A1 : Integer;
            A2 : Integer;
         when Msg_B =>
            B : Float;
      end case;
   end record;

-- This is my current workaround.

type Msg_A_Variant is
   record
      A1 : Integer;
      A2 : Integer;
   end record;

type Data_Type1(Msg : Msg_Type := Msg_A) is
   record
      case Msg is
         when Msg_A =>
            A : Msg_A_Variant;
         when Msg_B =>
            B : Float;
      end case;
   end record;

-- end workaround

pragma Unchecked_Union(Data_Type1);

<snip>




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

* Re: GNAT Unchecked_Union and multiple components
  2005-04-18 14:58 GNAT Unchecked_Union and multiple components Brian
@ 2005-04-20 21:03 ` Randy Brukardt
  0 siblings, 0 replies; 2+ messages in thread
From: Randy Brukardt @ 2005-04-20 21:03 UTC (permalink / raw)


"Brian" <brian.ngc@gmail.com> wrote in message
news:1113836280.439166.180090@f14g2000cwb.googlegroups.com...
> Hi,
>
> I've started to use GNAT 3.15p and noticed it handles the pragma
> Unchecked_Union differently from other compilers.  According to the
> GNAT Reference Manual "Each variant has a component list with a single
> component.", if you violate this rule the compiler will generate the
> error "Unchecked_Union variant can have only one component".  Other
> compilers allow multiple components per variant.

As does the upcoming Ada 2006.

> Is there a GNAT
> compiler switch I can use to loosen this restriction?

Not with GNAT 3.15p, but I believe the current versions of GNAT (which
others here can explain how to get better than I can) in fact support
Unchecked_Union as in the proposed Amendment to Ada (commonly known as Ada
2006 or Ada 2005).

             Randy Brukardt






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

end of thread, other threads:[~2005-04-20 21:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-18 14:58 GNAT Unchecked_Union and multiple components Brian
2005-04-20 21:03 ` Randy Brukardt

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