comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <no.spam@no.spam.com>
Subject: Re: Discriminated types with default discriminants
Date: Fri, 04 Nov 2005 10:18:37 +0100
Date: 2005-11-04T10:18:37+01:00	[thread overview]
Message-ID: <dkf91c$l5f$1@sunnews.cern.ch> (raw)
In-Reply-To: <U_saf.5294$Rl1.469@newsread1.news.pas.earthlink.net>

Jeffrey R. Carter wrote:

> Aside : begin
> 
> When I see something like this, I always wonder: What does a negative 
> Size mean?
> 
> To my mind, a negative Size is meaningless, and should not be allowed:
> 
> Size : Natural
> 
> end Aside;

Sure - no need to worry. :)
Just trying discriminated types: I picked Integer since the actual type 
would depend on the domain and without any particular domain (not even a 
homework) there was no reason to focus on type choices.


> There are 3 cases with discriminants:
> 
> 1. No default (object must be declared with explicit value)
> 2. Default, and object declared with explicit value
> 3. Default, and object declared without explicit value
> 
> The 1st 2 cases are equivalent. The object must always have the same 
> value for the discriminant. It can never change. The object is constrained.
> 
> The last case means the discriminant can change. The object is 
> unconstrained.

*Now* it all makes sense. I understand that for that last case the 
default discriminant value is actually used (I got an impression that 
it's not used at all), but is not considered to be fixed nor limiting - 
this is what "unconstrained" means in this context. It is the 
discriminant's *type* that defines the range of sizes for the final 
object and that's why I got the warning about the possibility of getting 
storage error.

This:

    subtype MyInt is Integer;
    type Discriminated(Size : MyInt := 10) is

makes the warning go away (GNAT's "feature" - as explained by Dmitry), 
but does not change anything from the language point of view - the 
potential size of the object still depends on MyInt'Last and if the 
actual object is unconstrained, we get memory allocation problem due to 
the fact that GNAT chooses one particular way of managing memory for 
unconstrained objects.

Thanks for the explanation.

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



  parent reply	other threads:[~2005-11-04  9:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-03 15:50 Discriminated types with default discriminants Maciej Sobczak
2005-11-03 16:06 ` Martin Krischik
2005-11-03 23:10   ` Robert A Duff
2005-11-04  5:01     ` Jeffrey R. Carter
2005-11-03 16:21 ` Ed Falis
2005-11-03 17:28 ` Dmitry A. Kazakov
2005-11-03 18:51 ` Jeffrey R. Carter
2005-11-03 23:08   ` Robert A Duff
2005-11-04  0:08     ` Adam Beneschan
2005-11-29  2:49       ` Randy Brukardt
2005-12-02 18:22         ` Robert A Duff
2005-11-04  9:18   ` Maciej Sobczak [this message]
2005-11-04  3:27 ` Brian May
2005-11-04 13:09   ` Stephen Leake
2005-11-04 17:58   ` Martin Krischik
replies disabled

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