comp.lang.ada
 help / color / mirror / Atom feed
From: David Botton <david@botton.com>
Subject: Re: why can't we declare unconstrained objects ?
Date: Wed, 15 Dec 2004 08:39:41 -0500
Date: 2004-12-15T08:39:41-05:00	[thread overview]
Message-ID: <2004121508394116807%david@bottoncom> (raw)
In-Reply-To: fa59671.0412120743.5cc44da6@posting.google.com

Here is an example from GNATCOM (http://www.gnavi.org) of a C/C++ style union

   subtype Variant_Range is Positive range 1 .. 41;

   --  NOTE: The Which values are completely bogus and have no significance

   --        The type of the variant can not be determined using it

   --        The values bellow do NOT correspond to correct variant type

   --        constants!

   type Variant_Union (Which : Variant_Range := 1) is

      record

         case Which is

            when 1 =>

               lVal      : Interfaces.C.long;

            when 2 =>

               bVal      : Interfaces.C.unsigned_char;

            when 3 =>

               iVal      : Interfaces.C.short;

            when 4 =>

               fltVal    : Interfaces.C.C_float;

            when 5 =>

               dblVal    : Interfaces.C.double;

            when 6 =>

               boolVal   : VARIANT_BOOL;

            when 7 =>

               bool      : VARIANT_BOOL;

            when 8 =>

               scode     : Types.SCODE;

            when 9 =>

               cyVal     : CURRENCY;

            when 10 =>

               date      : Types.DATE;

            when 11 =>

               bstrVal   : BSTR;

            when 12 =>

               punkVal   : Pointer_To_IUnknown;

            when 13 =>

               pdispVal  : Pointer_To_IDispatch;

            when 14 =>

               parray    : Pointer_To_SAFEARRAY;

            when 15 =>

               pbVal     : Pointer_To_BYTE;

            when 16 =>

               piVal     : Pointer_To_short;

            when 17 =>

               plVal     : Pointer_To_long;

            when 18 =>

               pfltVal   : Pointer_To_C_float;

            when 19 =>

               pdblVal   : Pointer_To_double;

            when 20 =>

               pboolVal  : Pointer_To_VARIANT_BOOL;

            when 21 =>

               pbool     : Pointer_To_VARIANT_BOOL;

            when 22 =>

               pscode    : Pointer_To_SCODE;

            when 23 =>

               pcyVal    : Pointer_To_CURRENCY;

            when 24 =>

               pdate     : Pointer_To_DATE;

            when 25 =>

               pbstrVal  : Pointer_To_BSTR;

            when 26 =>

               ppunkVal  : Pointer_To_Pointer_To_IUnknown;

            when 27 =>

               ppdispVal : Pointer_To_Pointer_To_IDispatch;

            when 28 =>

               pparray   : Pointer_To_Pointer_To_SAFEARRAY;

            when 29 =>

               pvarVal   : Pointer_To_VARIANT;

            when 30 =>

               byref     : Pointer_To_Void;

            when 31 =>

               cVal      : Interfaces.C.char;

            when 32 =>

               uiVal     : Interfaces.C.unsigned_short;

            when 33 =>

               ulVal     : Interfaces.C.unsigned_long;

            when 34 =>

               intVal    : Interfaces.C.int;

            when 35 =>

               uintVal   : Interfaces.C.unsigned;

            when 36 =>

               pdecVal   : Pointer_To_DECIMAL;

            when 37 =>

               pcVal     : Pointer_To_char;

            when 38 =>

               puiVal    : Pointer_To_unsigned_short;

            when 39 =>

               pulVal    : Pointer_To_unsigned_long;

            when 40 =>

               pintVal   : Pointer_To_int;

            when 41 =>

               puintVal  : Pointer_To_unsigned;

         end case;

      end record;

   pragma Convention (C_Pass_By_Copy, Variant_Union);

   pragma Unchecked_Union (Variant_Union);



   Size_Of_VARIANT : constant := 128;



   type VARIANT is

      record

         vt         : VARTYPE;

         wReserved1 : Interfaces.C.unsigned_short;

         wReserved2 : Interfaces.C.unsigned_short;

         wReserved3 : Interfaces.C.unsigned_short;

         u          : Variant_Union;

      end record;

   for VARIANT'Size use Size_Of_VARIANT;

   pragma Convention (C_Pass_By_Copy, VARIANT);

   --  The automation type VARIANT is used to create a variable that

   --  can contain any of the OLEAUTOMATION types. The value of vt

   --  indicates the type currently held in the type union in u

   --  Variants should be manipulated using the Variant APIs or with

   --  GNATCOM.Variant



   type Pointer_To_VARIANT_Constant is access constant VARIANT;





  parent reply	other threads:[~2004-12-15 13:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-12 15:43 why can't we declare unconstrained objects ? Michael Mounteney
2004-12-12 17:39 ` Martin Krischik
2004-12-12 17:47 ` Dmitry A. Kazakov
2004-12-12 18:21 ` Martin Dowie
2004-12-12 18:40   ` Jeffrey Carter
2004-12-12 19:24     ` Dmitry A. Kazakov
2004-12-15 13:39 ` David Botton [this message]
2004-12-15 21:47   ` 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