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.4 required=5.0 tests=AC_FROM_MANY_DOTS,BAYES_00 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!news2.google.com!news.maxwell.syr.edu!newsfeed.vmunix.org!newsfeed.hanau.net!news-fra1.dfn.de!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.bahnhof.se!feeder1.news.jippii.net!nntp.inet.fi!inet.fi!ash.uu.net!infeed.jaring.my!attdv1!ip.att.net!newsfeed1.global.lmco.com!svlnews.lmms.lmco.com!not-for-mail From: "Xenos" Newsgroups: comp.lang.ada Subject: Re: "Must instantiate controlled types at library level." Why? Date: Fri, 14 May 2004 15:40:56 -0400 Organization: Hades Message-ID: References: <13392802.3gDeTK7ybb@linux1.krischik.com> <2780491.NPbR8AFya6@linux1.krischik.com> <11924003.IfRfnULeIG@linux1.krischik.com> <1676457.GMYvKY1ieA@linux1.krischik.com> <1616198.O4tUV8TdF7@linux1.krischik.com> NNTP-Posting-Host: 158.187.64.144 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Xref: controlnews3.google.com comp.lang.ada:592 Date: 2004-05-14T15:40:56-04:00 List-Id: "Martin Krischik" wrote in message news:1616198.O4tUV8TdF7@linux1.krischik.com... > Xenos wrote > > > "Martin Krischik" wrote in message > > news:1676457.GMYvKY1ieA@linux1.krischik.com... > >> Freejack wrote: > >> 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. > > > Wrong. C++ has a string class in its standard library. Its a lot more > > versitile than Ada's String type. > > We are comparing languages capabilities here not libraries. the C++ string > class in not build into the language. Yes, I conceded that when someone else commented. > > >> 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. > > > Wrong. In certain situations, an array will "degrade" to a pointer to its > > element type. As a function parameter int X[] will degrade to a constant > > pointer to an integer, or int * const. It is NEVER eqvilent to char*. > > You must be thinking of Classic C (before the standard) were a char* was > > used at > > the generic pointer type before void* was introduced. A generic pointer > > will accept any type of (non-function) pointer, but is still not > > equivilent to it. > > No, You are am mistaken. Try this: > > class X > { > f (int *const x); > f (int x[]); > } > > Practical value is what counts. This just proves what I said above about degrading (or decaying if you prefer) pointers, and does not validate you saying that int X[] is the same as a char*. > > > It is only during degradation that an array end is unknown to the > > compiler. > > The array bounds become unknown. Well, you have proven my point. It is even > worse: Sometimes "sizeof X" will be the size of the array sometimes it is > just the size of an pointer. No, not sometimes. There are explicit rules for when this happen; it is not willy-nilly. If you say sizeof X, and X is an array type, you will ALWAYS get the size of the array. The function example won't get you out of this. Arrays in C/C++ are not first-class citizens and cannot be functions parmeters. Saying foo(int x[]) does not define x as an array type, so of course sizeof x will equal sizeof(int*). > > > C++ has the vector (et. al.) where .begin() and .end() are > > equivalent to 'First and 'Last. > > Again: vector is library not language. Again, I concede. > > >> 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. > > > Wrong. C++ has reference types are equivalent to "in out." Constant > > reference types may be used for "in." > > References are just "*const" with automatic referencing / dereferencing. > Syntactic sugar no new semantic. You can even do: > > Some_Class& X = *new Some_Class; > > delete &X; > This proves nothing other than you can create a pointer to an object and deference it. It also show that operators attached to a reference type act upon what is referenced, not the reference itself. References are more than just automatic pointers, and even so, when it comes down to it, "pass by reference" in Ada is still no more than a "hidden pointer." > Does work. Did it hundreds of times. If you use reference as class members > the compiler will stop creating copy constructors and warn you if you > forget to assign data inside the constructor. > This is because as I said above references are not just automatic pointers. They cannot be changed, so the compiler does not know how to create a copy constructor for you. You may still create one yourself, but you still cannot change the reference. Its the same as if you have other constant, non-mutable members. > > If you don't understand a language, you don't have any grounds to lambaste > > it. > > Just for the record: I have 10 years+ experience in C/C++ programming. I > know which bugs I have hunted. I know when the dam compiler turned my > arrays into pointer when I did not want, did not need it. Thank you very > much. > > And this is why I am here in this Ada group: I only program C/C++ when I get > paid for it and not one line for my private needs. > > With Regards > > Martin > -- > mailto://krischik@users.sourceforge.net > http://www.ada.krischik.com >