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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ec21c3c7cdc7ff3e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Alex R. Mosteo" Newsgroups: comp.lang.ada Subject: Re: private types Date: Tue, 14 Mar 2006 09:47:10 +0100 Message-ID: <4416830E.50201@mailinator.com> References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 0ouQwA8IkmPyMed8Nj4DsQO6pYWozOQD3REkinb0635aoFyEc= User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013) X-Accept-Language: en-us, en In-Reply-To: Xref: g2news1.google.com comp.lang.ada:3352 Date: 2006-03-14T09:47:10+01:00 List-Id: Brian May wrote: >>>>>>"Jeffrey" == Jeffrey R Carter writes: > > >> MyInteger to be made visible outside the scope of PrivateType ? > >> Doesnt it make the code less secure(for example,consider an > >> "uninitialized" object of type PrivateType.MyInteger). > > Jeffrey> Because that's what private means in Ada. > > He does have a point though - some languages will initialise all > variables to dummy values - this means you can get predictable results > in code that (wrongly) uses them before setting them to a value. > > In this case it is possible to force initialisation (at least outside > the package), as per another poster's suggestion, because it is a > private type. Alternatively it is possible to turn it into a record > type and provide a default value for the component, as per another > post. > > In other cases it isn't so easy, e.g. any non-private non-record type. > > In fact, by default (at least last time I checked), gcc (or was that > gnat) doesn't check the validity of parameters to functions if the > type matches, even though the type hasn't been initialised and may > just happen to contain an illegal value. > > I seem to recall Ada will initialise access types to null, and record > components (if defaults given), but nothing else. Access variables are initialized to null by language definition. Normalize_Scalars pragma exists also, and Gnat has Initialize_Scalars I think. These can give more control, but IMHO that's an after-the-bug resort.