comp.lang.ada
 help / color / mirror / Atom feed
From: Per Sandberg <per.sandberg@bredband.net>
Subject: Re: using the 'use at' feature inside a record?
Date: Thu, 10 Sep 2009 05:17:33 +0200
Date: 2009-09-10T05:17:33+02:00	[thread overview]
Message-ID: <%c%pm.68767$Ne3.5147@newsfe15.ams2> (raw)
In-Reply-To: <8f6142f2-ea37-46d7-a29c-0498da5dd9da@t13g2000yqn.googlegroups.com>

Well there are always unchecked unions:
    "ARM B.3.3 Pragma Unchecked_Union"
---------------------------
    type foo (dummy : Integer := 0) is record
       case dummy is
       when 1 =>
          as_integer              : integer;
       when 2 =>
          as_float                : Short_Float;
       when 3 =>
          as_String               : String (1 .. 4);
       when others =>
          as_Stream_Element_Array : Ada.Streams.Stream_Element_Array (1 
.. 4);
       end case;
    end record;
    pragma unchecked_Union(foo);
---------------------------

The above construct will is an exact equivalent of C's unions.

/Per


PForan wrote:
> Hi all,
> 
> I have a question about the "use at" feature and how it can be used
> inside a record to simulate C's unions. I often have an array of
> bytes, as well as a string which is "use at"'ed on top of the byte
> buffer, very useful as I can play with the data in any way I choose.
> i.e.
> 
> byte_buf: array(1..100) of unsigned_8;
> str_buf: string(1..100);
> for str_buf use at byte_buf'address;
> 
> Is it possible to have something like this within a record?
> 
> TIA,
> Phil



  reply	other threads:[~2009-09-10  3:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-09 20:07 using the 'use at' feature inside a record? PForan
2009-09-10  3:17 ` Per Sandberg [this message]
2009-09-10 23:42 ` Stephen Leake
2009-09-11 13:54   ` PForan
replies disabled

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