From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ab132517972acd5f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Fri, 24 Feb 2006 15:41:15 -0600 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: Subject: Re: accessing record element (question to the pros) Date: Fri, 24 Feb 2006 15:46:05 -0600 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-rtZyp5FhYkANtB+zPCPI+laGPkgMRIkuEZasA/ZaXNZp/T3q0nZbgTcGzoERRDvqMDZBqUPVHJ+9Dno!34BcdEuR307uUfUHAv7d14ssb+nKVYMF1keYOq3cX9CKRue8V11WbxhHXEojQwz1MpiEIn53Mkjd X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:3151 Date: 2006-02-24T15:46:05-06:00 List-Id: "Simon Wright" wrote in message news:m2oe0w7f3c.fsf@grendel.local... > "Jeffrey R. Carter" writes: > > > 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 > (http://gcc.gnu.org/onlinedocs/gcc-4.0.2/gnat_rm/Pragma-Unchecked_005fUnion. 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.