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-14 02:39:54 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!148.122.208.68!news2.oke.nextra.no!nextra.com!news1.oke.nextra.no.POSTED!not-for-mail Sender: ohk@maestro.clustra.com Newsgroups: comp.lang.ada Subject: Re: C-style 'union' in Ada? References: <9l7qon$d78$1@nntp9.atl.mindspring.net> <7E0e7.12187$vW2.6599957@news1.sttln1.wa.home.com> <9la73h$vvs$1@slb6.atl.mindspring.net> <3b78d2d4$1@pull.gecm.com> From: Ole-Hjalmar Kristensen Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 194.143.59.98 X-Complaints-To: news-abuse@nextra.no NNTP-Posting-Date: Tue, 14 Aug 2001 11:39:07 MET DST Organization: Nextra Public Access X-Trace: readme.online.no 997781947 194.143.59.98 Date: 14 Aug 2001 11:39:40 +0200 Xref: archiver1.google.com comp.lang.ada:11899 Date: 2001-08-14T11:39:40+02:00 List-Id: "Martin Dowie" writes: > The trick (if you could call it that!) is to include a default value > for the discriminant in the type definition. You can then change its > value at will. If you don't have a default then you have to contraint > the object when you declare it - which then fixes it to that value. Yes, but you can only change it with a whole record assignment. > > Brian Catlin wrote in message > news:9la73h$vvs$1@slb6.atl.mindspring.net... > > 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... > [snip] > > > 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; > > > > -- Kabelsalat ist gesund. Ole-Hj. Kristensen