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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a3471634bf10bf8d X-Google-Attributes: gid103376,public From: Joel VanLaven Subject: Re: private type discriminants ignored? Date: 1998/04/24 Message-ID: <3540cb0b.0@news4.his.com>#1/1 X-Deja-AN: 347349815 Sender: Joel VanLaven References: Organization: OC Systems Newsgroups: comp.lang.ada Date: 1998-04-24T00:00:00+00:00 List-Id: Jay Sachs wrote: [message trimmed for content] : type Stack(Size : Integer := 100) is record : Top : Natural := 0; : Rep : stackrep(1..Size); : end record; : I get warnings (from gnat 3.10) saying that I may get a storage_error : by creating a variable of type stack. I do in fact get such an error : if I declare : s : Stacks4.Stack; : However, supplying the initialization as in : s2 : Stacks4.Stack(75); : with no error. What is the reason that the default initialization : seems to be ignored in the discriminant for the private type? Default initializations of the type you are using have a very special meaning in Ada. They indicate that the constraint can be changed. Objects declared like s are sometimes referred to as "mutable" meaning that one can assign to them a value with a constraint other than 100. Essentially, there are three ways objects get their constriant: explicitly (forever constained to that value like 75 above) by initialization (forever constained like a : string := "abcd" will always have length 4) by default (mutable, can be changed, un-constrained like s above) Many (most, all?) compilers implement this by allocating (I'm using that term loosely) the maximum possible space needed to represent an object of the type with any constraint. So, s is of size on the order of magnitude of integer'last. Not good. If size was of some type that ranged from 1 to 200 GNAT would likely make s of size on the order of 200 and everything would be fine. I don't think you really want mutable objects here. It can be useful but is one of the trickier and fancier features in Ada, and I don't think it is what you are looking for. -- Joel VanLaven -- (I just happen to work for OC Systems)