Newsgroup: comp.lang.c++
Subject: Proposed Standard Change: inline this
From: W Karas <wkaras@...>
Date: Wed, 11 Dec 2013 09:34:41 -0800 (PST)
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. In which case, this optimization would save the execution of few/no instructions.
Another point against is that this change, like templates, would drive more Java-esqe class declarations with all the member functions defined inline.
Subject: Proposed Standard Change: inline this
From: W Karas <wkaras@...>
Date: Wed, 11 Dec 2013 09:34:41 -0800 (PST)
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. In which case, this optimization would save the execution of few/no instructions.
Another point against is that this change, like templates, would drive more Java-esqe class declarations with all the member functions defined inline.
via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?148867-Proposed-Standard-Change-inline-this&goto=newpost
View all the progranning help forums at:
http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums
No comments:
Post a Comment