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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7f2ce8bda9cae4ab X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail From: Martin Krischik Newsgroups: comp.lang.ada Subject: Re: "Must instantiate controlled types at library level." Why? Date: Fri, 14 May 2004 09:13:39 +0200 Organization: AdaCL Message-ID: <1676457.GMYvKY1ieA@linux1.krischik.com> References: <13392802.3gDeTK7ybb@linux1.krischik.com> <2780491.NPbR8AFya6@linux1.krischik.com> <11924003.IfRfnULeIG@linux1.krischik.com> Reply-To: krischik@users.sourceforge.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.t-online.com 1084519087 06 26106 edy2GwqrHG6jVIL 040514 07:18:07 X-Complaints-To: usenet-abuse@t-online.de X-ID: TFpJgaZCwe3Cv-1HE4FUfH1tEYb4qVx3tdQph9+2SlFgXoXCj+WekS User-Agent: KNode/0.7.7 Xref: controlnews3.google.com comp.lang.ada:576 Date: 2004-05-14T09:13:39+02:00 List-Id: Freejack wrote: > On Thu, 13 May 2004 13:18:11 +0200, Martin Krischik wrote: > >> I almost never use pointers in Ada since I can pass 'Class types around >> as I like. >> > Huh? > >> Martin > > Alright. I'm not a guru by any stretch of the imagination. But I do get > around Ada code quite proficiently. This idea of substituting Classes for > pointers is a bit fuzzy to me. I mean, a pointer is an address. Maybe I > don't understand Ada Classes as well as I thought. Simple Mantra: 'Class behaves like String. If you compare with C/C++: You always have to uses char* pointers since C/C++ has no equivalent for String. In C an array is either definite "int X[10]" or you use pointer. "int X[]" is only another syntax for "char*" since there is no 'First and 'Last in C/C++. Ada however has indefinite types - so pointers arn't neede here. Also you use pointers because C/C++ has no "out" or "in out". Ada however decides itself if call by value or call by reference is needed. So no pointers needed here as well. Back to the mantra: You can't say: S : String; C : Tagged_Type'Class; type S_Array is array (Natural range <>) of String; type C_Array is array (Natural range <>) of Tagged_Type'Class; But you can say: S : String := "Hello!"; C2 : Tagged_Type'Class := C1; procedure Do_S (Some_S : in out String); procedure Do_C (Some_C : in out Tagged_Type'Class); > Classes are addresses > too? No, like Strings they use memory. Actualy in the example above C2 might even allocate more memory then C1 since C2 as an indefinite type need to keep track of its size. With Regards Martin -- mailto://krischik@users.sourceforge.net http://www.ada.krischik.com