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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1042f393323e22da X-Google-Attributes: gid103376,public From: clines@delete_this.airmail.net (Kevin Cline) Subject: Re: Any research putting c above ada? Date: 1997/05/18 Message-ID: <12871CEBFAB00ABE.93483F73373D0261.D1086334F6EF8ED8@library-proxy.airnews.net>#1/1 X-Deja-AN: 242804944 References: <208C9C61CA05C32B.65D82DC950AAA33A.D68E7B27EB42E98A@library-proxy.airnews.net> <3372D44E.5F44@sprintmail.com> <337813DF.598C@dynamite.com.au> <337D3AE4.28F7@dynamite.com.au> <337E5854.1366@sprintmail.com> X-Orig-Message-ID: <337e8fec.3081017@news.airmail.net> Organization: INTERNET AMERICA NNTP-Proxy-Relay: library.airnews.net Newsgroups: comp.lang.ada Date: 1997-05-18T00:00:00+00:00 List-Id: "John G. Volan" wrote: >Kevin Cline wrote: >> >> Alan Brain wrote: >> >> >Simple really, and a real example. Nary a pointer or access type >> >anywhere. >> >> Someone has to manage that storage. Presumably in this case it is the >> run-time library. So the pointers exist in the generated code, even though >> hidden from the user. > >Nope, you're in the weeds here. A mutable record (discriminated record >with default initialization on the discriminant(s)) can be implemented >by simply providing it with enough space to house the largest possible >variant. It might not use all that space all the time, but it won't have >to allocate/reallocate anything. > >Bottom line, if you declare one of these beasts in the ordinary way, >your Ada compiler can certainly allocate it on the stack, and pass it >back and forth on the stack. Of course, that's trivial to do, and extremely impractical if the object is usually small but can occassionally be very large. Remember the original problem that started this thread? The poster claimed that it was easy to write a program that read a file into an array of lines since Ada allowed arrays of size determined at run-time to be returned as function values. The I pointed out that: 1. Most files do not begin with a line count. That's certainly a ridiculous requirement for manually prepared input. 2. Returning such an object is very inefficient because most compilers copy the entire object. Now you tell me that variable-length arrays can easily be handled in Ada without dynamic storage allocation. But then you indicate that the arrays are not truly variable in size, but are restricted to a compiled-in maximum size. That's fine for embedded applications where the amount of data to be handled is carefully defined ahead of time. It's useless for desk-top applications, where the size of the data to be handled, and the physical resources available to handle it vary widely from user to user. For those applications, you must resort to truly dynamic data structures, and Ada's arrays are of little use. This is one of the biggest blind spots I observed in experienced Ada programmers in a shop a few years ago. Ada programmers tend to use arrays instead of more dynamic data structures, resulting in inefficient and inflexible applications. OTOH, I have observed that the availability of the C++ STL containers is already expanding the toolkit of average C++ developers.