[lkml]   [1999]   [Jan]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: C++ in kernel (was Re: exception in a device driver)
And lo, Khimenko Victor saith unto me:
> >>
> >>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 ...

A correct compiler could not skip passing this, because it can not be known
until link time that this will not be needed. I don't know of a compiler
that leaves enough info in the .o file for the linker to optimize at that
stage...and would never take the time to do so.

> Programmer should do this
> by hand by declaring foofunc as static :-)

Amen...and it's not like you have occasion to do so all that often.


"Well, look at that. The sun's | Linux: |"Zooty,
coming up." -- John Sheridan, | KDE: | zoot
"Sleeping in Light", Babylon 5 | Keith: | zoot!" | | --Rebo

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:49    [W:0.054 / U:18.384 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site