Path: utzoo!mnetor!uunet!husc6!mit-eddie!uw-beaver!tikal!hplsla!jima From: jima@hplsla.HP.COM ( Jim Adcock) Newsgroups: comp.lang.c++ Subject: const, reference "this" revisited ??? Message-ID: <6590014@hplsla.HP.COM> Date: 27 Jan 88 06:05:27 GMT Organization: HP Lake Stevens, WA Lines: 30 This is kind of restating mdt's comments at the C++ workshop, but it seems like an awful shame that you can't get the same kind of control over "this" as other passed parameters to C++ functions. For example in: A::d() {this->a(); this->b(); this->c();}; whatever C++ compiler you're using is going to have to assume that a(), b(), and c(), could have modified the value of "this", so for example, after a() is called, the compiler is going to have to generate code to reload "this" into a register, then use "this" to load "this"'s vtable pointer into a register, then use the vtable pointer offset to load the address of b into a register, then jump to subroutine b .... then it has repeat the whole process again after b() is called in order to call c()...... whereas if a() and b() could declare that they don't change "this", then the whole process of loading "this" into a register, then using "this" to get the vtable pointer, etc would only have to be done once. What if C++ allowed [but did not require] "this" to be explicetly declared as "const" or "reference" in the declaration of a member function? [Don't ask me what the syntax would be, maybe just explicetely declared as if the first parameter in the passed parameter list] Seems like there are a LOT of situations where a compiler could generate much better code if it just could be told that "this" is not modified in the called member functions.