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,LOTS_OF_MONEY 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 20:49:52 PST Path: archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newsfeed1.earthlink.net!newsfeed2.earthlink.net!newsfeed.earthlink.net!news.mindspring.net!not-for-mail From: "Brian Catlin" Newsgroups: comp.lang.ada Subject: Re: C-style 'union' in Ada? Date: Mon, 13 Aug 2001 20:49:04 -0700 Organization: Sannas Consulting Message-ID: <9la73h$vvs$1@slb6.atl.mindspring.net> References: <9l7qon$d78$1@nntp9.atl.mindspring.net> <7E0e7.12187$vW2.6599957@news1.sttln1.wa.home.com> NNTP-Posting-Host: a5.f7.f1.c3 X-Server-Date: 14 Aug 2001 03:49:05 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4807.1700 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Xref: archiver1.google.com comp.lang.ada:11886 Date: 2001-08-14T03:49:05+00:00 List-Id: I didn't know that a discriminant could be assigned at run time. This is close to what I want to do. Thanks! -Brian "DuckE" wrote in message news:7E0e7.12187$vW2.6599957@news1.sttln1.wa.home.com... > Here is a comparable definition (I put it in a small program to make sure it > compiled :-) > I didn't include a separate length field since you don't really need it with > Ada. The length of the string may be found using > "str.ansi_string.all'length" or "str.wide_string.all'length". > > Note that a default descriminant is used for the record such that the type > of the record may be changed dynamically at run time (by assigning the whole > record). > > > with Ada.Strings.Unbounded; -- Defines String_Access and Free > use Ada.Strings.Unbounded; > with Ada.Strings.Wide_Unbounded; -- Defines Wide_String_Access and Free > use Ada.Strings.Wide_Unbounded; > > procedure string_demo is > > type str_type is ( ansi, wide ); > > type string_desc( str_select : str_type := ansi ) is > record > case str_select is > when ansi => > ansi_string : String_Access; > when wide => > wide_string : Wide_String_Access; > end case; > end record; > > begin > declare > str : string_desc; > begin > str := ( str_select => ansi, ansi_string => new String'( "Hello" ) ); > Free( str.ansi_string ); > str := ( str_select => wide, wide_string => new Wide_String'( > "There" ) ); > Free( str.wide_string ); > end; > end string_demo; > > > I hope this helps, > SteveD