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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,13703514e3723cbe X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-08-16 15:35:14 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed2.news.rcn.net!rcn!newsfeed1.earthlink.net!newsfeed.earthlink.net!newsmaster1.prod.itd.earthlink.net!newsread2.prod.itd.earthlink.net.POSTED!not-for-mail From: David Brown Subject: Re: C-style 'union' in Ada? Newsgroups: comp.lang.ada References: <9l7qon$d78$1@nntp9.atl.mindspring.net> User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (Linux/2.4.4-xfs (i686)) Message-ID: Date: Thu, 16 Aug 2001 22:35:34 GMT NNTP-Posting-Host: 64.133.74.64 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.prod.itd.earthlink.net 998001334 64.133.74.64 (Thu, 16 Aug 2001 15:35:34 PDT) NNTP-Posting-Date: Thu, 16 Aug 2001 15:35:34 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net X-Received-Date: Thu, 16 Aug 2001 15:32:22 PDT (newsmaster1.prod.itd.earthlink.net) Xref: archiver1.google.com comp.lang.ada:12020 Date: 2001-08-16T22:35:34+00:00 List-Id: Ted Dennison wrote: > In article <9l7qon$d78$1@nntp9.atl.mindspring.net>, Brian Catlin says... >> >>I'm still trying to get both lobes around the Ada paradigm. I have a >>record that I want to hold a pointer to a buffer which is either a String >>or Wide_String, but I don't want to statically declare which, so using a >>variant record won't work (at least given my understanding). Likewise, I >>don't want to have two record definitions, one for String, and one for >>Wide_String. In the package I'm designing, I don't care whether it is a >>String or Wide_String, I will just pass it to the file I/O packages >>(stream, in this case). In C, I would: > Thirdly, if I *did* have to have something like this for some reason > (which right now I cannot fathom), I'd probably define two structures (no > more or less work than defining one structure with both of them in it), > and use pointer-based unchecked_conversion to change my view of the > buffer between them. But its more likely I'd find a way to structurally > arrange things so that I didn't need to do that... I have recently encountered a concrete example of the need for something like this. The application is storing variable sized data fields in fixed length records (say disk sectors). The block is defined as a large string. The beginning of the block contains lengths for each of the variable sized fields. The data items start at the end of the record and work their way backward. Basically, there are two different views of the block and the boundary between them depends on the sizes of the data items. Unchecked conversions of access values seems to be the easiest way to deal with this. Dave Brown