Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 30 Dec 96 00:07:35 +0100
From:      cracauer@wavehh.hanse.de (Martin Cracauer)
To:        francisco@natserv.com
Cc:        freebsd-chat@freebsd.org
Subject:   Re: Comments on using C++ instead of C
Message-ID:  <9612292307.AA03374@wavehh.hanse.de>
References:  <199612290152.UAA28924@revelstone.jvm.com>

next in thread | previous in thread | raw e-mail | index | archive | help
"Francisco Reyes" <francisco@natserv.com> wrote:

>I have never programmed for Unix before and am about to start a small
>project. I was wondering if there are any advantages of using C over
>C++.

First of all, FreeBSD has working support for a reasonable complete
C++ implementation. See other replies to get going.

In general, almost all platforms have more mature C than C++ compilers
(Win32 maybe an exception). 

In particular, the gcc used for C and C++ on FreeBSD and being the
only compiler choice on this platform 
- doesn't offer all optimizations of C for C++
- Doesn't support full most rescent C++ (exceptions)
- Has some problems with existing features

The C part of gcc is very stable. Reusable modules you write in C
using gcc will not be outdated because of new language features
becoming aviliable sometime in future.

Another drawback of C++ vs. C on most platforms and FreeBSD in
particular is that much more people use the C part of gcc. It is being
tested to death and the remaining bugs are quite well-known,
workarounds exist and you generally know what you're going to tangle
with. The C part is used by almost every FreeBSD developer. The C++
part is used much except for one non-frequently changed base package
(groff) and some ports. In addition, the number of people
understanding the C++ part of gcc is basically none outside the (gcc,
not FreeBSD) developer's cycles, where the C part is quite accessible
for mortals.

Both C and C++ are languages you typically use instead of higher
languages when you want a perfect implementation and care for every
byte or instruction wasted. You can't do so if your compiler doesn't
play with you. You need an almost perfect compiler and g++ isn't. 

If you are going to contribute code to FreeBSD, especially kernel
code, you've got a better change that is will be accepted when it is
written in pure C.

I wont start listing everything counting against C++ in general, even
assuming perfect implementations on every platform you want. If you'd
write a short description why you want to use C++, I'd be able to
point out some drawbacks in private email (that doesn't mean C++ isn't
good for anything, but the range where it is the best choice - IMHO,
of course - is more narrow than most people think).

In other words: C and C++ are both languages that are relativly tight
coupled on the underlying machine. They are typically used in
applications where the problem is well-understood and the work to be
done is building the most efficient sequence of CPU instructions from
the specification and experimentation about proper solution is not
needed at all. My personaly impression is that if you understand the
problem to such an extend in advance, you can use C as well as C++
(you could also use assembler, if that would be portable). If you
really need a higher abstraction level, you better use other
languages.

Sorry for some bad spelling, its late. Hope is the useful
nothingtheless. 

Martin
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin_Cracauer@wavehh.hanse.de http://cracauer.cons.org  Fax.: +4940 5228536
"As far as I'm concerned,  if something is so complicated that you can't ex-
 plain it in 10 seconds, then it's probably not worth knowing anyway"- Calvin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9612292307.AA03374>