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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c022fc5445abd13d X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!irazu.switch.ch!news-zh.switch.ch!switch.ch!cernne03.cern.ch!cern.ch!news From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Discriminated types with default discriminants Date: Fri, 04 Nov 2005 10:18:37 +0100 Organization: CERN - European Laboratory for Particle Physics Message-ID: References: NNTP-Posting-Host: abpc10883.cern.ch Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sunnews.cern.ch 1131095916 21679 (None) 137.138.37.241 X-Complaints-To: news@sunnews.cern.ch User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20050922 Red Hat/1.7.12-1.1.3.2.SL3 X-Accept-Language: en-us, en In-Reply-To: Xref: g2news1.google.com comp.lang.ada:6178 Date: 2005-11-04T10:18:37+01:00 List-Id: 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/