comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <no.spam@no.spam.com>
Subject: Re: Correct use of variants
Date: Tue, 08 Nov 2005 09:40:22 +0100
Date: 2005-11-08T09:40:22+01:00	[thread overview]
Message-ID: <dkpo9m$c3o$1@sunnews.cern.ch> (raw)
In-Reply-To: <ubr0w6n7d.fsf@acm.org>

Stephen Leake wrote:

>>but I might have difficulty deciding which value is better than the
>>others for this role. 
> 
> It makes absolutely no difference. The syntax makes it look like you
> are giving a default value to the discriminant, but it doesn't matter
> what value you put; it will never be used.

Yes, it will be used:

type Discriminated(Which : Chooser := First) is -- ...

A : Discriminated;

-- later:

Put(A.X); -- OK, because the First part is in use,
           -- even though X is not initialized (you get garbage)

Put(A.Y); -- CONSTRAINT_ERROR at run-time


> I usually use:
> 
> type Foo_Type (descrim : Descrim_Type := Descrim_Type'first) is ...;
> 
> to indicate that I don't care what the default descriminant is.

Indeed, looks to be self-documenting.


Thank you for this and other responses.

-- 
Maciej Sobczak : http://www.msobczak.com/
Programming    : http://www.msobczak.com/prog/



      reply	other threads:[~2005-11-08  8:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-07 10:32 Correct use of variants Maciej Sobczak
2005-11-07 12:52 ` Jean-Pierre Rosen
2005-11-07 19:46 ` Jeffrey R. Carter
2005-11-07 23:40 ` Stephen Leake
2005-11-08  8:40   ` Maciej Sobczak [this message]
replies disabled

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