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,ec21c3c7cdc7ff3e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news2.volia.net!news.germany.com!news.belwue.de!news.uni-stuttgart.de!carbon.eu.sun.com!btnet-feed5!btnet!news.btopenworld.com!not-for-mail From: Mark Lorenzen Newsgroups: comp.lang.ada Subject: Re: private types Date: Mon, 13 Mar 2006 20:27:28 +0000 (UTC) Organization: BT Openworld Message-ID: References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> NNTP-Posting-Host: host86-135-159-155.range86-135.btcentralplus.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com 1142281648 10541 86.135.159.155 (13 Mar 2006 20:27:28 GMT) X-Complaints-To: news-complaints@lists.btinternet.com NNTP-Posting-Date: Mon, 13 Mar 2006 20:27:28 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 Xref: g2news1.google.com comp.lang.ada:3345 Date: 2006-03-13T20:27:28+00:00 List-Id: ada_student@yahoo.com writes: > Consider the following package declaration, > > package PrivateType is > > type MyInteger is private; > > procedure Read(O : out myInteger); > procedure Write(I : in MyInteger); > > private > > type MyInteger is range 1 .. 2**31 - 1; > > end; > > Why does Ada allow 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). First of all: If you want to learn about Ada, I can recommend the book "Programming in Ada 95" by John Barnes. I think that I understand what you are trying to do... You want to prevent the user of your package from declaring uninitialised variables of type PrivateType.MyInteger, right? In this case I would declare the partial view of the type (the non-private part) to be indefinite: type MyInteger (<>) is private; And then declare a function to provide an initial value of that type: function Nil returns MyInteger; The user of your package can then only declare a variable of type PrivateType.MyInteger if she initialises it at the same time: with PrivateType; [...] My_Var : PrivateType.MyInteger := PrivateType.Nil; Again: A good textbook on the subject will give you a much better understanding of the language than just trying to find Ada equivalents of C++ intricacies. - Mark