Re: Compiling C++ modules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux