Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Mar 97 13:48:32 +0200
From:      cracauer@wavehh.hanse.de (Martin Cracauer)
To:        moncrg@dominus.ma.ultranet.COM
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: C++ Code in Kernel
Message-ID:  <9703301148.AA06383@wavehh.hanse.de>
References:  <01BC3BA3.6FFD23A0@dominus.ultranet.com>

next in thread | previous in thread | raw e-mail | index | archive | help
>maybe its just that I'm taking a c++ class now, but I'm
>cusious as to the pro's and con's on writing kernel source
>in c++.  I haven't seen nor heard on this happening on FreeBSD
>[but then my travels haven't been that wide]

My current list of argument against C++:

- The compilers in general and g++ in special are not as mature as the
  C equivalents. We have enough problems with gcc itself that show up
  in deep system space (like floating-point - handling).

- The performance characteristic of C++ in general is less predictable
  than for pure C. It is very easy to use constructs that end up being
  compiled to code with hidden extra work. And even worse in practice,
  it is quite easy to write wrong code when trying to avoid these
  hidden costs.

- The performance characteristic of g++ is surprisingly often
  different from that of gcc for the same code. g++ disables some
  optimizations and aligns data often quite different than gcc does. I
  have done some little benchmarks, let me know if you want them.

  It is not that g++ is really slower than gcc for C, the disabled
  optimizations are not too effective for my code anyway and the other
  effects of g++ cause faster code in some place, too. But our kernel
  hackers can't reuse their compiler experience that easy.

- C++ is a very complicated language and using it (read: using some
  real C++ features) would make it fundamentally more difficult to let
  new developers hack on the code. The most dramatic effect (IMHO) is
  that error messages in C++ are very often a quite esoteric
  abstraction from the real problem.

- You can reuse C code in other languages as you want. This is several
  numbers of magnitude more difficult in C++ because of name mangling,
  constructors and destructors of static data, initialization of
  virtual function tables etc etc etc.

- C++ code is more diffucult to browse, to search for definitions and
  declarations, to present to the user in a debugger and such. Many if
  not all FreeBSD developers use self-constructed browse tools and
  couldn't reuse them for C++.

Don't misunderstand me: C++ is a nice tool for a lot of things and I
sheduled it for use in some projects of mine. Especially the STL,
despite some bloating problems, enables quite some code compression
for me. I use languages like Common Lisp and C++ when I have to start
coding before I really understand the problem I have to write a
program for. That is usually the case in almost every project I get
payed for, noone can expect customers to give straigt outline of a
project in a domain they do their first project in, which in turn
applies to 70% of my work.

But when I have the strong will to do something really really right, I
use C and nothing else than C. For example, when I need a collection
class code for several data types, I don't want templates to expand
them. I think over it where casting or macros or code duplication is
applicable and use the right one in every place. And build normal
libraries so that the code isn't constructed everytime I compile the
program. I know I didn't do it right when compile time prohibits
developing on my old Sparc 1 (no joke). And last but not leat, I can
use C libraries in Common Lisp and C++.

I clearly want FreeBSD's kernel code to be of the way outlined in the
last paragraph.

Martin

P.S. When some OO features are really useful, maybe for constructing
device driver or network protocol families with inheritance and
runtime lookup of functionality, I would think Objectve-C is a better
bet. Objective-C is just a C library for message calls and some
syntactic shugar to constructs calls to messages in source code. You
can even leave out all the syntactic stuff and do everything ObjC and
its runtime can do from plain C code. You just link in the runtime
which is a plain C library and a brave citizen inside other code of
every kind.
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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?9703301148.AA06383>