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,c406e0c4a6eb74ed X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!wn14feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail From: Dave Thompson Newsgroups: comp.lang.ada Subject: Re: ADA Popularity Discussion Request Message-ID: References: <49dc98cf.0408110556.18ae7df@posting.google.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 26 Aug 2004 05:22:17 GMT NNTP-Posting-Host: 12.76.14.140 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1093497737 12.76.14.140 (Thu, 26 Aug 2004 05:22:17 GMT) NNTP-Posting-Date: Thu, 26 Aug 2004 05:22:17 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:3008 Date: 2004-08-26T05:22:17+00:00 List-Id: On Tue, 17 Aug 2004 09:50:07 +0200, "Dmitry A. Kazakov" wrote: > On 16 Aug 2004 14:09:41 -0700, Keith H Duggar wrote: > > > "Ada was an experiment that failed. It was specified in such a way > > that it's hard to get adequate performance. > > Theoretically Ada has better support for optimizations than C. For example, > in C you can get pointer to any object. This assumes that compiler is > restricted in how and where it allocates them. In Ada an object has to be In C if you declare with storage-class 'register' its address cannot be taken and so it cannot be aliased, since C also does not have call-by-reference. This is not quite as easy and not as clear, but it works. But not in C++; there 'register' exists for compatibility with C but is overridden by prefix&. For a local or 'static' (private to source file/module ~= package) variable, even if not declared register, the compiler can usually determine that its address is never taken or at least never exported. In C99 you can declare a pointer 'restrict' meaning the compiler may assume its target is unaliased (within scope) -- but it's your (the programmer's) responsibility to ensure that, it doesn't check for you. > "aliased" to allow that. Another example is > > for Index in A'Range loop > A (I) := ... -- There is no need to check array bounds > Of course in C there aren't required to be, and almost never are, any bounds checks in the first place. Nor in C++ for builtin arrays, but you can get them with std::vector or your own array-like classes. > Yet another example, in C++ any call to a virtual function is dispatching. > In Ada it is only when the object is class-wide. For an OO application the > difference in terms performance could be huge. > See below. > > Or are there simply missing features that preclude some > > efficient coding idioms (does Ada have pointers?). I'm > > very ignorant when it comes to Ada so please forgive these > > newbie questions. > > Yes, Ada has pointers, and interestingly, because that wasn't design > intent, richer than C++ has. > > 1. Ada has specific and class-wide pointers. In C++ all pointers are > class-wide. Dereferenced class-wide pointers dispatch on member functions. > In Ada you have a choice. > C++ pointers and references are polymorphic, but you can "narrow" them for a specific call by ptr-> /* or ref . */ base:: method (args). > 2. Ada has anonymous pointers. It is difficult to find any equivalent in > C++, because it has many limitations Ada does not have. It is something > like: > > class X // This is not C++! > { > public : > friend void Foo (int Something, virtual X * This); > > 3. Ada has pool-specific and general access pointers. A rough C++ > equivalent would be operators new and operator delete. But Ada is more > flexible here, its "new" is attached not to the object type, but to the > pointer one. So you can have many pools of objects of same type. > Yep. You can write your own pool-bound pointer type (sub)classes in or for a class in C++ if you want, and I think even a (nondefault) operator new that selects them, something like the (optional, and AFAIK rarely used) 'allocator's on standard library containers and streams. You would get locality and free-all-at-once, but it is very unlikely the compiler would figure out to make them pool-relative and give you optimized representation or access. Except, for the very restricted case of (sub)allocating within a array of fixed or bounded size you could make a smart "pointer" that is really just a subscript. > 4. Ada pointers are true types. In C++ pointers have structure equivalence. More: all C++ constructed types (pointer, reference, array, function) have structural equivalence except named (or uniquely typedef'ed) classes, unions, and enums. > The difference appears when building large libraries. Consider objects of > type X to be sorted using different ways. In Ada you can: > > type X_By_Name is access X; -- Pointer to X > function "<" (Left, Right : X_By_Name) return Boolean; > -- Dereferences and compares names > > type X_By_Value is access X; -- Another pointer to X > function "<" (Left, Right : X_By_Values) return Boolean; > -- Dereferences and compares values > > Now, you can instantiate a Sort procedure once with X_By_Name and its "<" > and once with X_By_Value and its "<". The result is two different sorts > with no extra control parameters to pass and no subsequent parameter > checks. > Not as conveniently, but you can write pointer classes that are distinct types yet collapse (inline if you like) to actual pointers: struct X { int y,z; }; class X_By_y { X* x; public: /*ctor*/X_By_y (X* xx) : x(xx) {} int operator< (X_By_y that) { return x->y < that.x->y; } }; class X_By_z { X* x; public: /*ctor*/X_By_z (X* xx) : x(xx) {} int operator< (X_By_z that) { return x->z < that.x->z; } }; > 5. Ada pointers are transparent to member extraction and array indexing. > I.e. in Ada "->" and "." are same. Again you can write a smart pointer to do this if you want, but I consider it only a minor convenience. - David.Thompson1 at worldnet.att.net