* using the 'use at' feature inside a record?
@ 2009-09-09 20:07 PForan
2009-09-10 3:17 ` Per Sandberg
2009-09-10 23:42 ` Stephen Leake
0 siblings, 2 replies; 4+ messages in thread
From: PForan @ 2009-09-09 20:07 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: using the 'use at' feature inside a record?
2009-09-09 20:07 using the 'use at' feature inside a record? PForan
@ 2009-09-10 3:17 ` Per Sandberg
2009-09-10 23:42 ` Stephen Leake
1 sibling, 0 replies; 4+ messages in thread
From: Per Sandberg @ 2009-09-10 3:17 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: using the 'use at' feature inside a record?
2009-09-09 20:07 using the 'use at' feature inside a record? PForan
2009-09-10 3:17 ` Per Sandberg
@ 2009-09-10 23:42 ` Stephen Leake
2009-09-11 13:54 ` PForan
1 sibling, 1 reply; 4+ messages in thread
From: Stephen Leake @ 2009-09-10 23:42 UTC (permalink / raw)
PForan <pforan@gmail.com> writes:
> 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?
'use at' is obsolete (LRM J.7); you should now use:
for str_buf'address use byte_buf'address;
If you are implementing an Ada variant record type that must match a C
union type that has no field for the discriminant, use pragma
Unchecked_Union (LRM B.3.3).
--
-- Stephe
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: using the 'use at' feature inside a record?
2009-09-10 23:42 ` Stephen Leake
@ 2009-09-11 13:54 ` PForan
0 siblings, 0 replies; 4+ messages in thread
From: PForan @ 2009-09-11 13:54 UTC (permalink / raw)
On Sep 10, 7:42 pm, Stephen Leake <stephen_le...@stephe-leake.org>
wrote:
> PForan <pfo...@gmail.com> writes:
Thanks a bunch for the replies all. I had no clue that 'use at' was
considered old, the new syntax is definetly clearer. Time to go
play :)
Cheers!
Phil
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-09-11 13:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-09 20:07 using the 'use at' feature inside a record? PForan
2009-09-10 3:17 ` Per Sandberg
2009-09-10 23:42 ` Stephen Leake
2009-09-11 13:54 ` PForan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox