Re: accessing record element (question to the pros)
- From: "Randy Brukardt" <randy@xxxxxxxxxxxxxx>
- Date: Fri, 24 Feb 2006 15:46:05 -0600
"Simon Wright" <simon@xxxxxxxxxxxx> wrote in message
news:m2oe0w7f3c.fsf@xxxxxxxxxxxxxxxx
"Jeffrey R. Carter" <spam@xxxxxxxx> writes:(http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gnat_rm/Pragma-Unchecked_005fUnion.
However, in general, you can't do what you seem to be trying to
do. Variant records do not allow unchecked type conversion; the
language rules prohibit it. That's what Ada.Unchecked_Conversion is
for.
GNAT (certainly in recent versions) has pragma Unchecked_Union
html#Pragma-Unchecked_005fUnion).
NB, compiler-specific.
It is present in a number of Ada 95 compilers (at least the Ada
Magic-derived ones as well as GNAT), and is part of Ada 2005 (see
http://www.adaic.com/standards/05rm/html/RM-B-3-3.html). So it's not really
compiler-specific.
OTOH, Unchecked_Union is *only* intended for interfacing to C. In
particular, using it to get the effect of Unchecked_Conversion is strongly
discouraged. Indeed, any such use is defined to be erroneous (see the Note
at the end of B.3.3 - there's no explicit rule because it follows from the
rules for check suppression). It might work, but a compiler could raise an
exception or reformat your hard disk as well...
If you want this to work reliably, use Unchecked_Conversion. I don't endorse
tricks with 'Address, either, because they can confuse optimizers and are
just too tricky to understand for the maintenance programmers to follow. Ada
has a special dispensation that Unchecked_Conversion doesn't have to make a
copy (unlike other functions), so there's really no good reason for using
tricky overlays. If Unchecked_Conversion is too slow, lean on your compiler
vendor!!
Randy.
.
- Follow-Ups:
- many thanks to all the people who give me useful hints!
- From: Norbert Caspari
- many thanks to all the people who give me useful hints!
- References:
- accessing record element (question to the pros)
- From: Norbert Caspari
- Re: accessing record element (question to the pros)
- From: Jeffrey R. Carter
- Re: accessing record element (question to the pros)
- From: Simon Wright
- accessing record element (question to the pros)
- Prev by Date: Re: Records that could be arrays
- Next by Date: Re: limited types (Was: Records that could be arrays)
- Previous by thread: Re: accessing record element (question to the pros)
- Next by thread: many thanks to all the people who give me useful hints!
- Index(es):
Relevant Pages
|
|