W
W Karas
An instance x of class X could be declared with this syntax:
inline this X x;
This would potentially affect the object code generated a call x.mem(...), mem() a member function of X which was defined inline. The compiler could simply inline the function call. But if it didn't, the above declaration would cause the compiler to "consider" generating and calling object code for mem() with the hard-coded address of x in place of the (eliminated) implied "this" parameter. The compiler could further "consider" cascading this behavior to member functions, defined inline, that are directly or indirectly called by mem().
It's not unusual for classes to have only one instance of the class in a program. It this case, it seems wasteful to be passing the "this" parameter over and over with a never-changing value. One can make all class members static, or use a namespace "pseudo-class". But that seems a akin to using macros as alternatives to inline functions. Object code optimization should (ideally) either be automatic, or only require a minimal hint added to source code describing logical behavior. Also, this facility might be a useful optimization in cases where there are a small number of instances (greater than 1) of X in the program.
If you find this syntax unaesthetic, I agree, I'm very open to suggestions for alternatives.
On the other hand, I suspect, for typical contemporary architectures, generated object code may use a "dedicated" register for the "this" pointer. Inwhich case, this optimization would save the execution of few/no instructions.
Another point against is that this change, like templates, would drive moreJava-esqe class declarations with all the member functions defined inline.
inline this X x;
This would potentially affect the object code generated a call x.mem(...), mem() a member function of X which was defined inline. The compiler could simply inline the function call. But if it didn't, the above declaration would cause the compiler to "consider" generating and calling object code for mem() with the hard-coded address of x in place of the (eliminated) implied "this" parameter. The compiler could further "consider" cascading this behavior to member functions, defined inline, that are directly or indirectly called by mem().
It's not unusual for classes to have only one instance of the class in a program. It this case, it seems wasteful to be passing the "this" parameter over and over with a never-changing value. One can make all class members static, or use a namespace "pseudo-class". But that seems a akin to using macros as alternatives to inline functions. Object code optimization should (ideally) either be automatic, or only require a minimal hint added to source code describing logical behavior. Also, this facility might be a useful optimization in cases where there are a small number of instances (greater than 1) of X in the program.
If you find this syntax unaesthetic, I agree, I'm very open to suggestions for alternatives.
On the other hand, I suspect, for typical contemporary architectures, generated object code may use a "dedicated" register for the "this" pointer. Inwhich case, this optimization would save the execution of few/no instructions.
Another point against is that this change, like templates, would drive moreJava-esqe class declarations with all the member functions defined inline.