Messages in this thread | | | Subject | Re: C++ in kernel (was Re: exception in a device driver) | Date | Tue, 12 Jan 1999 00:38:00 -0600 (EST) | From | kwrohrer@ce ... |
| |
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 ld.so 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.
Keith
-- "Well, look at that. The sun's | Linux: http://www.linuxhq.com |"Zooty, coming up." -- John Sheridan, | KDE: http://www.kde.org | zoot "Sleeping in Light", Babylon 5 | Keith: kwrohrer@enteract.com | zoot!" www.midwinter.com/lurk/lurker.html | http://www.enteract.com/~kwrohrer | --Rebo
- 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/
| |