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-13 00:34:06 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!news1.rdc1.sfba.home.com.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: C-style 'union' in Ada? References: <9l7qon$d78$1@nntp9.atl.mindspring.net> X-Newsreader: Tom's custom newsreader Message-ID: Date: Mon, 13 Aug 2001 07:34:06 GMT NNTP-Posting-Host: 24.7.82.199 X-Complaints-To: abuse@home.net X-Trace: news1.rdc1.sfba.home.com 997688046 24.7.82.199 (Mon, 13 Aug 2001 00:34:06 PDT) NNTP-Posting-Date: Mon, 13 Aug 2001 00:34:06 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:11832 Date: 2001-08-13T07:34:06+00:00 List-Id: >record that I want to hold a pointer to a buffer which is either a String >or 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: How *do* you tell which it is? Or do you really truly neither know nor care? If so, then the pointer itself is the abstraction level - it's a black box of bits. It could just as well be an integer, or an array of bytes, whatever. If you do have a way to tell, can you incorporate that as a discriminant in a variant record? eg. type string_desc(Is_Wide : Boolean) is record length : Interfaces.C.Unsigned_Long; case Is_Wide is when True => ansi_string : String_Desc; when False => wide_string : Wide_String_Desc; end case; end record; of course struct { ... string_desc file_name; ... } some_struct; will in turn need a discriminant to pass along: type some_struct(Uses_Wide_String : Boolean) is record ... file_name : string_desc(Is_Wide => Uses_Wide_String); ... end record; It's possible that tagged types would be appropriate. An abstract parent type with primitive procedures declared for those operations that treat an object of the type as a black box, and abstract primitives for those operations that *must* be declared separately depending on the child type being ansi_string or wide_string.