Re: [PATCH] C++ breaks on linux/ioport.h

From: Sean Hunter (seanh@sportingbet.com)
Date: Sun Apr 30 2000 - 02:49:45 EST


> You also need to provide an interrupt safe, thread safe and smp safe lockless
> exception handling mechanism for the C++ exceptions. You can't really avoid
> that as you will want to do memory allocation and a memory allocation can
> and must fail gracefully.
>

I'd just like to emphasise that Alan is showing a greater knowlege of
C++ than its advocates here. Specifically, the Ansi C++ standard
requires that (for example) bad_alloc exceptions are thrown if c++
memory allocations fail.[1]

I love both C and C++, and have written at various times in both these
languages and others. I think the fundamental point here is that bad
C++ is written by people who pretend that C++ is the same as C. The
kernel is in C, and to say "why won't my C++ kernel module work", you
may as well ask "why won't my algol[2] kernel module work?". The fact
that C and C++ are similar does not make them the same. In fact, if
you read the ARM, you will see how, and why, the original design goal
of making C++ a superset of C was gradually compromised.

C++ is subtly different from C in lots of ways that would begin to
make kernel programming a nightmare if they were mixed. It has
different operator precedence, no default type promotion, different
rules about lexical scope of variables as well as the extra stuff that
might cause problems like the extra keywords, additional standard
types, references etc. While we can simply forswear the use of STL,
RTTI and user-defined exceptions, and subvert some of the restrictions
on system exceptions (by never using new and delete, for instance, or
by using the "nothrow" versions), the scoping things etc are features
of the language itself, and would cause subtle bugs.

Anyone who doesn't believe me that c and c++ are different should try
this:

[sean@henry /tmp]$ cat testx.c
#include <stdio.h>
  
main(){
    printf("I am a %s compiler\n", (sizeof 'A' == 1) ? "C++" : "C");
}
  
[sean@henry /tmp]$ gcc /tmp/testx.c ; ./a.out
I am a C compiler
[sean@henry /tmp]$ g++ /tmp/testx.c ; ./a.out
I am a C++ compiler
  
The above output is mandatory for all standards-compliant C and C++
compilers.

If people want to spend the effort to link the kernel with modules
written in various languages, its fine to do that, but they shouldn't
inflict those choices, or their corresponding problems on everybody
else. Obviously, userland libc5 programs in c++ should be able to
compile, but that's a given.

Sean

[1] Unless you use the "nothrow" versions of new and delete, (or
use the <cstdlib> functions)

[2] Or "Bournegol"?

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



This archive was generated by hypermail 2b29 : Sun Apr 30 2000 - 21:00:17 EST