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.6 required=5.0 tests=BAYES_00,TO_NO_BRKTS_FROM_MSSP 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-14 06:39:07 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!feed.textport.net!newsranger.com!www.newsranger.com!not-for-mail Newsgroups: comp.lang.ada From: Ted Dennison References: <9l7qon$d78$1@nntp9.atl.mindspring.net> Subject: Re: C-style 'union' in Ada? Message-ID: X-Abuse-Info: When contacting newsranger.com regarding abuse please X-Abuse-Info: forward the entire news article including headers or X-Abuse-Info: else we will not be able to process your request X-Complaints-To: abuse@newsranger.com NNTP-Posting-Date: Tue, 14 Aug 2001 09:38:53 EDT Organization: http://www.newsranger.com Date: Tue, 14 Aug 2001 13:38:53 GMT Xref: archiver1.google.com comp.lang.ada:11913 Date: 2001-08-14T13:38:53+00:00 List-Id: 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: First off, its wrong that you have to staticly declare which one you are using for a variant record. If you define the record to have a default value for the variant, then you can change it at runtime. The catch is that you have to change *all* the record fields along with the variant when you do it. Secondly, I don't ever end up with structures like this in my Ada code (unless I'm interfacing to some OS routine that uses them). I'm not saying that its impossible that you actually need this, just that its highly unlikely. Its even more unlikely that you really need a pointer to it. So you really ought to tell us *why* you feel like you need this structure. 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... --- T.E.D. homepage - http://www.telepath.com/dennison/Ted/TED.html home email - mailto:dennison@telepath.com