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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,d17561d7e5eba62c X-Google-Attributes: gid103376,public From: Mark A Biggar Subject: Re: An alternative to Unchecked Conversion Date: 1999/12/16 Message-ID: <38595FAE.C04A77E8@lmco.com>#1/1 X-Deja-AN: 561698718 Content-Transfer-Encoding: 7bit References: X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Lockheed Martin M&DS Western Region Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-12-16T00:00:00+00:00 List-Id: Tom_Hargraves@Raytheon.com wrote: > > Related to "Questions about Unchecked_Conversion". > > There have been some good responses to the related topic. I agree with the > sentiment that Unchecked_Conversion should be rarely if ever used. However if > you HAVE TO use it, it does come with an overhead. It is a routine which has to > be called, and it may end up copying data around and cost you cpu time. Most compilers implement Unchecked_Conversion as an implisit inlined routine with no more (actually less as there are no checks done) overhead then an assignment statement. > So when you HAVE TO, e.g. to copy Ada structures onto byte streams being > transmitted over a 'hardware' interface, there's another technique which has > been around for a while. In the fortran era it was implemented using the common > block and equivalence statements. > > The technique is simply to map the Ada structure directly onto the 'other' data > structure. > > It has the following advantages: > 1. It's fast, there is no data transfer 'cost'. > 2. The data structures can be different sizes. > > It has the following disadvantages: > 1. If your Ada structure contains constrained types, then a write to the > 'other' data structure can subsequently cause a constraint error when you come > to read the data. > 2. Timing and synchronisation become a issue if the reader and writer are not > in the same task/thread. 3. There is no guarentee in the LRM that it will work correctly (although most implementations will "Do The Right Thing"). So it definitely not protable, while Unchecked_conversion is Guarenteed to be. -- Mark Biggar mark.a.biggar@lmco.com