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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,13703514e3723cbe X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-17 11:50:45 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!titan03.ksc.nasa.gov!niven.ksc.nasa.gov!usenet From: "Samuel T. Harris" Newsgroups: comp.lang.ada Subject: Re: C-style 'union' in Ada? Date: Fri, 17 Aug 2001 13:45:06 -0500 Organization: Raytheon Aerospace Engineering Services Message-ID: <3B7D6632.F84CA345@gsde.hou.us.ray.com> References: <9l7qon$d78$1@nntp9.atl.mindspring.net> <9li279$mhm$1@slb2.atl.mindspring.net> Reply-To: samuel_t_harris@raytheon.com NNTP-Posting-Host: sstf-fw.jsc.nasa.gov Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.7 [en] (X11; U; IRIX64 6.2 IP19) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:12068 Date: 2001-08-17T13:45:06-05:00 List-Id: Ted Dennison wrote: > > In article <9li279$mhm$1@slb2.atl.mindspring.net>, Brian Catlin says... > > > >This is very similar to what I'm doing. I was trying to avoid unchecked > >conversion. I had assumed that there would be a better way. > > Well, converting between types is pretty much what Unchecked_Conversion is in > the language for. It may look a bit ugly and scary, but that's because the > activity you are doing is *also* a bit ugly and scary (if sometimes nessecary). > Consider it truth in advertising. :-) > > Note that since Unchecked_Conversion is a function, an assignment of the value > will occur. That's why we usually perform it on pointers when the target data is > large buffers. > Of course, using unchecked_conversion on pointers has its own brand of pitfalls. Consider the Rational R1000 machines where each access type involved very own storage pool and a pointer was actually an offset from the base address of that storage pool. In this environment it is meaningless to convert an access to an 8-bit integer to an access to an 8-bit character since the pointer of the character will dereference to a completely different memory location. In Ada 83, if one was assured that access types were compatible with system.address, then access types usually used a more conventional heap allocation and all was good with the code. However, in Ada 95, where I can create my own storage pools, then I may experience other problems using conversions between pointers. The "address" of the converted pointer may resolve to the same memory location, but is my storage pool is being used for access to controlled types and I convert it to some access to an non-controlled type, then my carefully construct, reference counting, garbage collection, storage pool mechanism is inviolated. I suppose converting a access to a non-controlled type into an access to a controlled type involving a storage pool would be even worse. That carefully constructed mechanism can quickly become insane from all the "false" dereferences. -- Samuel T. Harris, Senior Software Engineer II Raytheon, Aerospace Engineering Services "If you can make it, We can fake it!"