comp.lang.ada
 help / color / mirror / Atom feed
From: "Martin Dowie" <martin.dowie@nospam.baesystems.com>
Subject: Re: C-style 'union' in Ada?
Date: Tue, 14 Aug 2001 08:37:44 +0100
Date: 2001-08-14T08:37:44+01:00	[thread overview]
Message-ID: <3b78d2d4$1@pull.gecm.com> (raw)
In-Reply-To: 9la73h$vvs$1@slb6.atl.mindspring.net

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.

Brian Catlin <briancatlin@mindspring.com> 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" <nospam_steved94@home.com> 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;
>





  reply	other threads:[~2001-08-14  7:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-13  6:06 C-style 'union' in Ada? Brian Catlin
2001-08-13  7:34 ` tmoran
2001-08-14  3:09 ` DuckE
2001-08-14  3:49   ` Brian Catlin
2001-08-14  7:37     ` Martin Dowie [this message]
2001-08-14  9:39       ` Ole-Hjalmar Kristensen
2001-08-14 11:49         ` Martin Dowie
2001-08-14 13:38 ` Ted Dennison
2001-08-16 22:35   ` David Brown
2001-08-17  3:14     ` Brian Catlin
2001-08-17 14:44       ` Ted Dennison
2001-08-17 16:38         ` Jeffrey Carter
2001-08-17 18:17           ` Ted Dennison
2001-08-17 18:45         ` Samuel T. Harris
2001-08-17  3:18     ` Variable sizes for record fields (was: C-style 'union' in Ada) Larry Kilgallen
2001-08-17  6:34       ` Variable sizes for record fields David Brown
2001-08-17 10:44         ` Larry Kilgallen
2001-08-17 19:18           ` Warren W. Gay VE3WWG
2001-08-17 21:36             ` Ken Burtch
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox