Re: C++ in kernel (was Re: exception in a device driver)

Benjamin Scherrey (scherrey@gte.net)
Wed, 13 Jan 1999 15:06:21 -0500


Mr. Victor,
I've refrained from replying to your previous attacks on C++ but you continue to persist in a habit of
comparing C code with C++ code that is functionally and semantically different. The fact is that the ONLY
difference between a struct and a class in C++ is that classes have a default private scope for all its members.
In all of your examples I can recall you insist on declaring the methods as virtual yet you don't bother to write
code in your C example to support the same functionality (FYI - your C example is not an example of the
capabilities of a virtual call). Why do you insist that C++ methods be declared virtual?!?!? Additionally cout
and printf are no where near the same. If you want a direct comparison go ahead and use printf in your C++
examples or else you should implement a iostream capable equivalent of printf (not likely). All of your code
comparisons are examples of ignorance of C++ or plain intellectual dishonesty. Its also getting way offtopic
(which is why I even now hesitate to post this) because we've left behind the issue of linux kernel issues and
how the language features apply to it.

thanx & later,

Ben Scherrey

Khimenko Victor wrote:

> In <003101be3db0$d4d945e0$04c809c0@Fake.Domain.com> Anthony Barbachan (barbacha@Hinako.AMBusiness.com) wrote:
>
> AB> 1 - It does not lead to speed loss.
>
> It does. Take a look:
> -- C++ code --
> #include <iostream>
>
> class someclass {
> int i;
> public:
> explicit someclass(int _i) : i(_i) {}
> virtual foo() {
> std::cout << i << endl;
> }
> };
>
> void test(someclass& x) {
> x.foo();
> }
>
> void main (void) {
> someclass a(1);
> test(a);
> }
> -- C code --
> #include <stdio.h>
>
> struct someclass {
> int i;
> int (*foo)(struct someclass*);
> };
>
> int someclass_deffoo(struct someclass* x) {
> printf("%d\n",x->i);
> }
>
> /*
> * int someclass_otherfoo(struct someclass* x) {
> * printf("%d\n",x->i<<1);
> * }
> */
>
> void test(struct someclass* x) {
> x->foo(x);
> }
>
> int main (void) {
> struct someclass a={1,someclass_deffoo};
> test(&a);
> /*
> * a.foo=someclass_otherfoo;
> * test(&a);
> */
> return 0;
> }
> -- cut --

-
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/