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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,56131a5c3acc678e X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-11-27 10:35:48 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!elnk-pas-nf1!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread2.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Question about OO programming in Ada References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <8urxb.19482$sb4.18182@newsread2.news.pas.earthlink.net> Date: Thu, 27 Nov 2003 18:35:48 GMT NNTP-Posting-Host: 63.184.33.115 X-Complaints-To: abuse@earthlink.net X-Trace: newsread2.news.pas.earthlink.net 1069958148 63.184.33.115 (Thu, 27 Nov 2003 10:35:48 PST) NNTP-Posting-Date: Thu, 27 Nov 2003 10:35:48 PST Xref: archiver1.google.com comp.lang.ada:3000 Date: 2003-11-27T18:35:48+00:00 List-Id: Ekkehard Morgenstern wrote: > Thanks. That's good to know. What does "Unchecked_Access" do? In Ada, the emphasis is on creating correct software (as opposed to say, C, in which the emphasis is on getting something that runs as quickly as possible). So the default in Ada is "safe". Access values obtained by 'Access are safe: you cannot create a dangling reference with 'Access. But Ada is also intended for low-level, real-time software where sometimes you are sure something is safe but the compiler cannot be sure. For those cases, Ada has "Unchecked_" versions of things. The access value obtained by 'Unchecked_Access is not safe; it is possible to create dangling references with 'Unchecked_Access. You see the same sort of thing, for instance, in type conversions. A normal type conversion is checked and safe, but there's also Unchecked_Conversion, which typically does nothing (it means "interpret this collection of bits as this other type). > I still wonder if The_Registration is actually a reference, or is it the > object returned by Register()? > > I.e. if I wanted only a reference to the object, would I have to use an > access to Registration'Class? > > I wonder about this stuff because I'd like implement a linked list package, > which provides one set of subprograms for all types of derived linked lists > and list nodes. For the kind of stuff Eachus has been showing you, you shouldn't really care. About the only time you want to worry about this is if you're developing a dynamic data structure. Speaking of dynamic data structures, an unbounded list is such a beast, and of course you would want and need to use access types to implement one. > > Now, if I had a function like this: > > function Next( N : in out Node'Class ) return Node'Class; > > (btw, is it ok to use "in out" in this case with a function?) No. All parameters to functions have mode "in". I think there's no point in specifying the mode for function parameters, since the default is "in". > > Can I return an object of type Node'Class, or do I have to return an access > to it? You can return either, depending on what you're doing. Generally you'd want to return Node'Class. > > And the Node implementation, can it look like this: > > type Node is tagged limited > record > Succ : Node'Class; > Pred : Node'Class; > end record; No. You probably want type Node; type Node_Ptr is access Node; type Node is record Prev : Node_Ptr; Value : Element; Next : Node_Ptr; end record; where Element is the type of the thing you're storing in the list, probably a generic formal type. But you're probably better off using an existing list package than writing yet another list. >>(And you >>probably chose those packages from a library instead of "rolling your >>own.") > > What kind of library would you recommend to me? I'd need some linked lists, > queues, containers and so on, but I'd like to have versions that are > completely generic. There are a number of well-tested libraries listed at www.adapower.com and www.adaworld.com. I like the PragmAda Reusable Components http://home.earthlink.net/~jrcarter010/pragmarc.htm but I may be biased. -- Jeff Carter "Why don't you bore a hole in yourself and let the sap run out?" Horse Feathers 49