Re: Compiling C++ modules

James Courtier-Dutton
2006-04-25T10:23:39Z

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