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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,2e2db8edf2656165 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!news.cs.univ-paris8.fr!proxad.net!proxad.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Constructing an object Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Fri, 23 Sep 2005 14:04:29 +0200 Message-ID: NNTP-Posting-Date: 23 Sep 2005 14:04:25 MEST NNTP-Posting-Host: 4d8330d1.newsread4.arcor-online.net X-Trace: DXC=Z_`Ica5f8CAndh];1CKbgL:ejgIfPPldDjW\KbG]kaMHXY;eg@jLYeLUDIK0;NNWmN[6LHn;2LCVN7enW;^6ZC`D<=9bOTW=MNN X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:5057 Date: 2005-09-23T14:04:25+02:00 List-Id: On Fri, 23 Sep 2005 10:23:02 +0200, Maciej Sobczak wrote: > Is it really enough? Consider this: > > -- file shapes.ads > package Shapes is > type Color is (Black, White); > type Shape is private; -- or tagged private Replace it with: type Shape (<>) is private; BTW, private vs. tagged private is a huge difference. > function New_Shape(C : in Color) return Shape; > private > type Shape is record -- or tagged > C : Color; > end record; > end Shapes; > > -- file shapes.adb > package body Shapes is > function New_Shape(C : in Color) return Shape is > begin > return Shape'(C => C); -- I like this syntax :) > end New_Shape; > end Shapes; > > -- file hello.adb > with Shapes; > procedure Hello is > S : Shapes.Shape; -- oops, uninitialized Shape > begin > null; > end Hello; > > It compiles fine (GNAT) and it allows me to declare an uninitialized > object of private type Shape. The only thing that private type gives me > is that I cannot tinker with its internals directly. This is good in > itself, but not enough to save me from having uninitialized objects. It is enough if the public view is made up so that objects look unconstrained. This is what (<>) does. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de