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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news.tele.dk!news.tele.dk!small.news.tele.dk!news100.image.dk!news000.worldonline.dk.POSTED!not-for-mail From: "Peter Koch Larsen" Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1lr611thktbau$.1dj95z21h7l5v.dlg@40tude.net> <97kpu5gkgo1r$.kc4nx7cxjziw$.dlg@40tude.net> Subject: Re: [OT] Re: Teaching new tricks to an old dog (C++ -->Ada) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original Message-ID: Date: Fri, 11 Mar 2005 10:42:51 +0100 NNTP-Posting-Host: 62.79.147.244 X-Complaints-To: news-abuse@wol.dk X-Trace: news000.worldonline.dk 1110534170 62.79.147.244 (Fri, 11 Mar 2005 10:42:50 MET) NNTP-Posting-Date: Fri, 11 Mar 2005 10:42:50 MET Organization: Customer of Tiscali A/S Xref: g2news1.google.com comp.lang.ada:9119 comp.lang.c++:45102 comp.realtime:1263 comp.software-eng:4830 Date: 2005-03-11T10:42:51+01:00 List-Id: "Dmitry A. Kazakov" skrev i en meddelelse news:97kpu5gkgo1r$.kc4nx7cxjziw$.dlg@40tude.net... > On 11 Mar 2005 00:05:06 -0800, Alberto wrote: > >> "Dmitry A. Kazakov" wrote in message >> news:<1lr611thktbau$.1dj95z21h7l5v.dlg@40tude.net>... > >>> 3. The size of all exception objects has an upper bound. >> >> What is the advantage here? :) > > You can catch the exception Storage_Error! (:-)) Well of course you can do that in C++. > >>> But even then bounds checking is not needed for every access. Example: >>> >>> procedure Dynamic (A : Some_Array) is >>> subtype Index is Array_Index range A'Range; >>> J : Index := A'First; >>> >>> for I in A'Range loop >>> A (I) := .. -- No checks >>> ... >>> J := I; >>> end loop; >>> A (J) := ... -- Still no checks >>> >>> C++ completely lacks the notion of constrained subtypes which makes the >>> above possible. >> >> If Some_Array is any array supplied at run-time, how can the compiler >> know what values are stored in A'Range? (I mean, what the bounds of >> the array are) > > The bounds are in the array dope. > >> It *has* to check these bounds at run-time. This >> behaviour is also easily done with C++, creating a 'bounds' class, >> similar to A'Range. The only difference is that it is a mechanism >> provided by the user and not the compiler. > > No, the difference is that the compiler *statically* knows that both I and > J will be in the bounds at run-time. There is no way (except for dirty > tricks with casting) how they might become out of the bounds. Therefore > the > compiler can safely omit any checks. > >>>> 4. Also, some people wrote that C++ is bad because it is difficult >>>> (but not imposible, see Comeau C++) to follow 100% the Standard. The >>>> same can be said to adA, because at least if we own a compiler of the >>>> '83 Standard, we can't have the derivation a virtual function >>>> mechanisms, only interfaces (pure virtual classes)[2]. To me, it >>>> sounds reasonable to work with the last version of a compiler when >>>> possible. >>> >>> As long as you have only one compiler vendor... >> >> Sorry, I don't understand you very well here. > > If your code depends on the compiler version, and you have to compile it > under gcc, Borland, MSVC, then you are in trouble man! The answer is simple: just do not write code that depends on a particular compiler; write your code in C++. > >>> 2. C++ is unable to allocate objects of indefinite size on the stack. >> >> Well, we have alloca() for this ;) > > Try to return such object from a function. Ada can > > declare > Object : T'Class := Read_It_From_File; > > Here neither the specific type, nor the size of the object are known at > compile time. Another example: > > declare > Line : String := Read_Source_Line (File); > > Or even: > > Put_Line (Read_Source_Line (File)); The solution is simple here - just allocate your memory on the heap. In C++ the last example would be: std::string s; file.getline(s); > > -- > Regards, > Dmitry A. Kazakov > http://www.dmitry-kazakov.de