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

Khimenko Victor (khim@sch57.msk.ru)
Mon, 11 Jan 1999 22:50:31 +0300 (MSK)


In <018301be3d2d$1bd63b80$04c809c0@Fake.Domain.com> Anthony Barbachan (barbacha@Hinako.AMBusiness.com) wrote:

>>> The rest is FUD: it's trivial to "figure out" when you are passing a
>>> "self" pointer argument around: only non-static member functions have
>>> them.
>>
>>On the contrary
>>
>>
>>foo1.C
>>
>> blah->foofunc();
>>
>>
>>foo2.C
>>
>>blahobject::foofunc()
>>{
>> printf("Hi");
>>}
>>
>>a C++ compiler ends up passing "this" needlessly because it can't tell that
>>foofunc of object blahobject need not know who it is.
>>

> A good optimizing compiler should detect the lack of use of the this
> variable and optimize it away. Besides the reason "this" is passed to the
> function is to access object variables, so a C version of a C++ object would
> have its associated functions passed a structure's address as well.

Since C++ has no support for modular programming (shame for modern language)
aven genious compiler could not do anything with this sample. Since compiler
is NOT aware about lack of this usage in foofunc while compiling foo1.C and
thus could not remove it's usage there and thus could not remove it's usage
in foo2.C as well even if foofunc is not virtual ... Programmer should do this
by hand by declaring foofunc as static :-) So instead of writing some things
in program (like C case) with C++ programmer must always think about compiler
and what compiler will do with all definitions :-(( So stated goal: free
programmer mind from implementation details for other things is not accessed...

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