Re: Compiling C++ modules

From: James Courtier-Dutton
Date: Tue Apr 25 2006 - 06:23:29 EST


Avi Kivity wrote:


The "advantages" of the former over the latter:

(1) Without exceptions (which are fragile in a kernel), the former can't return an error instead of initializing the Foo.
Don't discount exceptions so fast. They're exactly what makes the code clearer and more robust.

A very large proportion of error handling consists of:
- detect the error
- undo local changes (freeing memory and unlocking spinlocks)
- propagate the error

Exceptions make that fully automatic. The kernel uses a mix of gotos and alternate returns which bloat the code and are incredibly error prone. See the recent 2.6.16.x for examples.
C++ exceptions are much more error prone than C. Well not exactly error prone, but more non-deterministic.
This is one of the reasons that Software standards allow C++ at lower levels, e.g. DAL E, but at higher levels, e.g. DAL B, C++ is not allowed, but C is.
So, one can conclude that a C program can be made more reliable than a C++ program. One aim of a kernel is reliability.

James
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/