[comp.lang.ada] C++ as a way to use private types in C

larry@JPL-VLSI.ARPA (03/19/87)

--
If you want private types in C the best way is to get a C++ to C translator. 
There are at least three available for the PC family and several for various
minis.  (I understand AT&T has compilers (as opposed to translators) for
some of their 3B computers also.)

C++ is very similar to Ada, except for tasking where the older C-style
facilities are used.  It's also upwardly compatible with C except for some
minor details; for instance, you can't use the about a half-dozen keywords
C++ uses.  It also has an advantage over Ada in that functions are data
objects, so can be passed as parameters, etc.

C++ also has a number of disadvantages, most fostered by a need to remain
compatible with C felt by its its designers (primarily Bjourne Stroustrup
but with a lot of input from the prime C theorists at AT&T).

Has anyone on the list done a detailed comparison between C++ and Ada?

               Larry @ jpl-vlsi.arpa

WELTY@GE-CRD.ARPA (WELTY RICHARD P) (03/19/87)

Date: 19-MAR-1987 11:01
From: Richard Welty
Sender: WELTY
Subject: Re: C++ as a way to use private types in C
To: info-ada@ada20.arpa@smtp, WELTY@CRDMAIL
--------

--------

bs@alice.UUCP (03/19/87)

> C++ is very similar to Ada, except ...

Please don't get the idea that C++ is a corporate planner's idea of
an Ada workalike. C++ has in various forms been in use for over 7 years.
It is essentially C with stronger type checking and Simula-like classes.
C++ also offers function and operator overloading (including overloading
of assignment, subscripting, and application). It does not provide generic
types directly. It provides C low-level efficiency and flexibility.

It differs from Ada not just in being a C superset, but also in its approach
to abstraction. The most fundamental difference is probably that C++ relies
on a class concept with inheritance rather than a package concept.

Concurrency issues were deliberately avoided in C++ because I felt that
for systems applications it was more important for the programmer to be
able to exploit the concurrency model of particular hardware and/or operating
systems directly than to get the convenience of a standard language supported
model of concurrency (that might be at odds with what the hardware provides).

C++ is in use on AT&T 3Bs, DEC VAXes, DG machines, HP 9000s, Amdahls, 80286
based machines (i.e. IBM-ATs and clones), 68K based machines (Suns, Apollos,
etc.), and sevaral other architectures.

> Has anyone on the list done a detailed comparison between C++ and Ada?

Not that I know of. It would be interesting to see one - especially one that
was not too detailed.

lomow@calgary.UUCP (Greg Lomow) (03/19/87)

In article <870318190934.056@Jpl-VLSI.ARPA>, larry@JPL-VLSI.ARPA writes:

> --
> If you want private types in C the best way is to get a C++ to C translator.

True

> C++ is very similar to Ada, 

C++ is very similar to Simula and Smalltalk, C++ is only similar to Ada
in ways that these languages are similar to Ada. C++ also enjoys many
of the advantages that these languages possess over Ada, such as:

> It also has an advantage over Ada in that functions are data
> objects, so can be passed as parameters, etc.

> C++ also has a number of disadvantages, most fostered by a need to remain
> compatible with C felt by its its designers (primarily Bjourne Stroustrup
> but with a lot of input from the prime C theorists at AT&T).

True

>                Larry @ jpl-vlsi.arpa

Greg Lomow

Usenet:    ....![ubc-vision,ihnp4]!alberta!calgary!lomow

WELTY@GE-CRD.ARPA (WELTY RICHARD P) (03/19/87)

Date: 19-MAR-1987 13:52
From: Richard Welty
Sender: WELTY
Subject: Re: C++ as a way to use private types in C
To: info-ada@ada20.arpa@smtp
--------
Argh!  This is a reconstruction of the earlier posting that I refered to
in an earlier posting (our mailer blew it ...)

> Larry @ jpl-vlsi.arpa writes:

>C++ is very similar to Ada, except for tasking where the older C-style
>facilities are used.

C++ contains a number of serious differences, actually ...

Objects in C++ (like objects in Flavors, CommonLoops, Smalltalk, etc.)
may be dynamically allocated and freed -- Ada Generics are a somewhat
weaker notion.  Also, C++ provides single inheritance (unfortunately,
it does not support multiple inheritance; its designers feel that multiple
inheritance has unacceptable performance penalties).

			-- Richard Welty (welty@ge-crd.arpa)

--------

firth@sei.cmu.edu.UUCP (03/20/87)

There is a comp.lang.c++ board on this machine,
and I suspect there's one on yours, too.  Could
you please send posts about c++ there, so that
those of us who have no interest in this language
can save wear on our 'n' keys?

bs@alice.UUCP (03/20/87)

In article <8703200117.AA10060@ucbvax.Berkeley.EDU>, WELTY@GE-CRD.ARPA.UUCP writes:
> 
> >C++ is very similar to Ada, except for tasking where the older C-style
> >facilities are used.
> 
> C++ contains a number of serious differences, actually ...
> 
> Objects in C++ (like objects in Flavors, CommonLoops, Smalltalk, etc.)
> may be dynamically allocated and freed -- Ada Generics are a somewhat
> weaker notion.  Also, C++ provides single inheritance (unfortunately,
> it does not support multiple inheritance; its designers feel that multiple
> inheritance has unacceptable performance penalties).

One of the ways C++ differs from Smalltalk and the object based
Lisps is in efficiency (typically differences in low-level efficiency is
measured in factors, not percents). To preserve this difference I avoid
inherently slow features like the plague. However, multiple inheritance
is not one of those. I have an experimental version of C++ with multiple
inheritance. The added overhead in calling a member function is one
memory reference plus one addition.

The snag is that I'm still not fully convinced that multiple inheritance
is a significant improvement over single inheritance. but I guess that
this is not the right newsgroup for that question.

len@geac.UUCP (Leonard Vanek) (03/20/87)

In article <870318190934.056@Jpl-VLSI.ARPA> larry@JPL-VLSI.ARPA writes:
>--
>If you want private types in C the best way is to get a C++ to C translator. 
>
>C++ is very similar to Ada, except for tasking where the older C-style ...
>
>Has anyone on the list done a detailed comparison between C++ and Ada?
>
I have written a semi-detailed comparison of C++ and Ada, which
includes both technical and non-technical considerations for
their use in developing commercial products. It is not based on
actual experience with either language -- only the reading of the
"official" books describing them and some discussion with users.
I am willing to mail a copy to anyone who is interested, or post it
if the interest is really high. It is about 8 pages in length.

By the way, I do not agree that C++ and Ada are all that similar,
but they do have some major features in common.

---------------------------------------------------------------------
Leonard Vanek                       phone (416) 475-0525
Geac Computers International
350 Steelcase Rd. West
Markham Ontario L3R 1B3
Canada

UUCP ... {allegra,ihnp4,decvax,pyramid} !utzoo!yetti!geac!len

gore@nucsrl.UUCP (03/21/87)

/ nucsrl:comp.lang.ada / WELTY@GE-CRD.ARPA (WELTY RICHARD P) /
> Objects in C++ (like objects in Flavors, CommonLoops, Smalltalk, etc.)
> may be dynamically allocated and freed -- Ada Generics are a somewhat
> weaker notion.

I'm not sure what you mean here.  My understanding is that you can instantiate
a generic within a scope, thus "dynamically allocating" it.  When you leave
the scope, it's gone, "dynamically freed"... sort of.  If the instance has
allocated heap space during its life, that space is not deallocated
automatically, but becomes the garbage collector's problem.

Unless there is no garbage collector;  then it becomes the programmer's
problem.  And the programmer doesn't have any elegant ways of solving it.

This is one of the features of C++ that I miss most in Ada:  constructors and
destructors.  It makes it unduly difficult to have abstract data types that
use dynamic storage -- both in assuring proper intialization, and in assuring
proper release.

Jacob Gore
Northwestern University, Computer Science Research Lab
{ihnp4,chinet}!nucsrl!gore

WELTY@GE-CRD.ARPA.UUCP (03/31/87)

Date: 31-MAR-1987 11:58
From: Richard Welty
Sender: WELTY
Subject: Re: C++ as a way to use private types in C
To: info-ada@ada20.isi.edu@smtp
--------
> ihnp4!chinet!nucsrl!gore@ucbvax.Berkeley.EDU  (Jacob Gore) writes:
>/ nucsrl:comp.lang.ada / WELTY@GE-CRD.ARPA (WELTY RICHARD P) /
>> Objects in C++ (like objects in Flavors, CommonLoops, Smalltalk, etc.)
>> may be dynamically allocated and freed -- Ada Generics are a somewhat
>> weaker notion.
>
>I'm not sure what you mean here.  My understanding is that you can instantiate
>a generic within a scope, thus "dynamically allocating" it.  When you leave
>the scope, it's gone, "dynamically freed"... sort of.  If the instance has
>allocated heap space during its life, that space is not deallocated
>automatically, but becomes the garbage collector's problem.

What I meant was that the objects are reasonably independent of scope --
I can allocate and free them in the course of normal execution, allocate
n of them inside of a loop, pass pointers to them, etc.  Ada has a distinctly
different style for handling this sort of thing.  You can use a package
to contain the type declaration for some object you want to declare along
with the functions for access to it.  In a system like C++, the functions
are considered to be a part of the object.  The resulting language has
a lot of interesting properties when it comes to things like scoping ...

			-- Richard Welty (welty@ge-crd.arpa)

--------