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,c04a86d57d8e19c4,start X-Google-Attributes: gid103376,public From: dewar@merv.cs.nyu.edu (Robert Dewar) Subject: C vs Ada code quality Date: 1997/04/24 Message-ID: #1/1 X-Deja-AN: 237067097 Organization: New York University Newsgroups: comp.lang.ada Date: 1997-04-24T00:00:00+00:00 List-Id: Someone asked me, but I lost the email address, because it bounced, the following (so I am not sure who asked) < writes: > Valentin asks > > < separate compilation - no inter-module annalysis / no > inter-procedure annalysis) ?>> > > If runtime checks are off, the answer is NO! Suppose I want to define the constructor/destructor for a type. In C++ I just define them. In Ada, I use the Finalisation type and I (as far as I understand) overide them thus the object will have tag (4 bytes long pointer ?); if the object is very small, this can be significant. Larger objects can slow down the program (larger blocks to allocate, more cache miss, more page faults). Ok this is a pretty small problem, but this is an example which can be part of 'distributed fat' (many small overheads which end-up slowing the program). This problem explainned has perhaps a solution (other then not using constructors/destructors) but this is just an idea. Also, I understand that it may be difficult to compare different compilers using different optimising methods. Any reasons why Ada could be faster (in theory, no real numbers required) then C or C++ when all checks are off ? ;-) >> A couple of important points here C IS NOT THE SAME LANGUAGE AS C++ ! This confusion is an amazingly common one. I made a statement about C, but the response assumes I was talking about C++, false! C++ has some high level constructs that do not necessarily map identically into Ada, so I would not make the same claim for C++ (that any program in C could be mapped identically into Ada). However, the example here is bogus. The contstructor/destructor mechanism in C++ is entirely analogous to the controlled type facility in Ada 95. There is nothing in Ada 95 that says that the tag is stored as part of the value -- note that in formal RM terms, the tag is NOT part of the value, and if you start thinking of it, even informally, as part of the value, you will find the RM confusing (for example, an assignment copies the value, but it does not copy the tag). An implementation of destructors and constructors in C++ may or may not add overhead to stored objects. An implementation of controlled types in Ada 95 may or may not add overhead to stored objects. In any case you are in the business of comparing implementations, not languages. <> Absolutely, consider the aliasing problem, in C, we write *q = 1; and if q is a *int, then without very hard analysis that in any case can never be entirely complete, we have to assume that any int values that are temporarily in registers may be destroyed. There are many other cases in which the "excessive" freedom of C pointers degrade the generated code. Now this does not mean that an Ada compiler *will* do a better job, but it means it could. For example, gcc does not do a very good job of aliasing analysis (partly because it is not so useful for C), so GNAT does not see this advantage -- but everyone knows that adding better aliasing analysis and data structures to gcc would be helpful, even for C, and when this is done, you will certainly be able to construct examples where Ada takes advantage of this and does better than is possible in C.