comp.lang.ada
 help / color / mirror / Atom feed
From: "Brian" <brian.ngc@gmail.com>
Subject: GNAT Unchecked_Union and multiple components
Date: 18 Apr 2005 07:58:00 -0700
Date: 2005-04-18T07:58:00-07:00	[thread overview]
Message-ID: <1113836280.439166.180090@f14g2000cwb.googlegroups.com> (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>




             reply	other threads:[~2005-04-18 14:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-18 14:58 Brian [this message]
2005-04-20 21:03 ` GNAT Unchecked_Union and multiple components Randy Brukardt
replies disabled

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