comp.lang.ada
 help / color / mirror / Atom feed
From: Valentin Bonnard <bonnardv@pratique.fr>
To: Robert Dewar <dewar@merv.cs.nyu.edu>
Subject: Re: C vs Ada code quality
Date: 1997/05/01
Date: 1997-05-01T00:00:00+00:00	[thread overview]
Message-ID: <3367C474.6ABA@pratique.fr> (raw)



Robert Dewar <dewar@merv.cs.nyu.edu> writes:

> <<I'm not a specialist of Ada, but it seem to me that the analogy
> is imcomplete since C++ rely on overloading (compile time)
> and Ada on overiding (run time).>>
> 
> Right, you are not a specialist in Ada, and your guesses are wrong. I will
> say this again, quite clearly this time I hope: The controlled types in
> Ada are exactly equivalent to the destructors in C++.

I don't understand how this can be.

> They involve
> dispatching only when it would also be neessary in C++. I don't know what
> leads to your misconceptions here, but they are misconceptions.

The fact that I believe that :

- tagged types can be used polymorphically thus have the vtable 
  pointer even if they aren't use polymorphically

- functions on tagged type are 'virtual', that is, they are 
  called based on the dynamic type

> Probably you are confusing the formal description with the implementation.
> The fact that controlled types in Ada are derived from controlled does
> not mean you have to implement them any differently from C++. 

Yes I assume they are implemented the same:

class Controled {
public:
    Controled ();
    // I don't how to write operator= here
    virtual ~Controled () = 0
        { } // if this syntax is allowed in C++, I'm not sure
};

This means that there is a runtime penatly in general for 
class derived from Controled (very localised and pretty 
small actually).

> <<No no no, I am *not* comparing a particular implementation>>
> 
> yes,yes,yes you *are* comparing a particular implementation. You just don't
> realize what the distinction is between what is required in the semantics
> and what a typical implementation uses to provide these semantics.

I am not; you are off base (or you want me to believe that).

Can you for example tell me an implementation which doesn't use 
a vtable ? (Of course details of the representation of the vtable 
can change a little.) Perhaps you know at special debugging 
implementation which doesn't use the vtable, but I'm talking 
about real compilers, not interpretors.

> In both Ada and C++, finalization (destructors) are defined on individual
> types, and have to be called at the right time. End of story, no significant
> difference! Now you may wonder why in practice C++ implementations have
> avoided the use of dynamic lists for finalization, and Ada implementations
> have often used them. The answer is simple. Once you have to deal with
> exceptions the dynamic list has real advantages -- the C++ world is
> working through these problems now -- for example, see the discussions
> with respect to g++ and exeptions, where recently someone seriously
> suggested the possibility of going to lists for handling destructors.

EH should be done with global walkback table; only the most 
basic implementation register the objects (the first 
implementation of EH in the first release that support it).

Modern EH doesn't slow down code that doesn't throw (or 
should I write raise, since we are in c.l.a ?); the other 
method, singnificatly easier to implement is that all 
object register and de-register all the time; this has 
an awfull abstraction penalty.

(Assuming exceptions are exceptionnals, which is true 
in real code in C++, but it is in Ada ?)

> <<But is it different in Ada ? Does the 'aliased' keyword really
> help ? Does this keyword serve any purpose (the compiler can
> look at the source to see if you are taking accesses to a
> variable directly) ? Is it like the register keyword in C (ie
> the semantic of a register variable is the same but you can't
> take its address) ?>>
> 
> Of course not! You are forgetting separate compilation -- the same problem
> of course arises in C. Yes, you can sometimes tell for local variables
> (e.g. in the absence of subunits), but in C and C++ global variables
> have to be assumed to be aliased, and this is not the case in Ada.

Ok, but for more flexible interfaces, shouldn't you declare 
everything aliased ?

Is Ada lower level than C/C++ in this respect (C++ 
programmers consider that the fact a variable is 
aliased is a low level detail) ? (While Ada 
operates at a clearly higher level than C/C++ wrt arg 
passing (IN/OUT vs T, T&, const T&, T*, const T* types).)

-- 

Valentin Bonnard
mailto:bonnardv@pratique.fr
http://www.pratique.fr/~bonnardv (Informations sur le C++ en Francais)




             reply	other threads:[~1997-05-01  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-05-01  0:00 Valentin Bonnard [this message]
  -- strict thread matches above, loose matches on Subject: below --
1997-04-24  0:00 C vs Ada code quality Robert Dewar
1997-04-26  0:00 ` Valentin Bonnard
1997-04-26  0:00   ` Robert Dewar
1997-04-29  0:00     ` Richard Kenner
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox