|Languages that give "hints" to the compiler jhummel@cy4.ICS.UCI.EDU (Joe Hummel) (1994-07-18)|
|Re: Languages that give "hints" to the compiler email@example.com (1994-07-29)|
|Re: Languages that give "hints" to the compiler firstname.lastname@example.org (1994-07-19)|
|Re: Languages that give "hints" to the compiler email@example.com (1994-07-21)|
|Re: Languages that give "hints" to the compiler firstname.lastname@example.org (1994-07-31)|
|Languages that give "hints" to the compiler email@example.com (1994-08-01)|
|Re: Languages that give "hints" to the compiler firstname.lastname@example.org (1994-08-02)|
|Re: Languages that give "hints" to the compiler email@example.com (1994-08-03)|
|From:||firstname.lastname@example.org (Steve Simmons)|
|Keywords:||C, C++, optimize|
|Organization:||CONVEX News Network, Engineering (cnn.eng), Richardson, Tx USA|
|Date:||Mon, 1 Aug 1994 12:30:08 GMT|
> Now to tell the truth, I know of no C or C++ compilers that currently make
> use of const qualification in this way, but I keep hoping. (If anyone
> else knows of compilers that *do* use const qualification in the manner
> I've described, please let me know.) Evidence of my hope may be seen
> frequently in my own (recent) code, which is littered with stuff with
> looks roughly like the following (for example):
The const qualifier is great; however, it would be a bad optimizer that
would key purely off the const qualifier. Why???? Const can be coerced/cast
away. Look at the following C++ code...
int foo::getValue() const
if (!valueInCache) ((foo*) this)->value = calculateValue();
const foo bar;
.... load all of bar's fields
int i = bar.getValue();
.... the value and valueInCache fields would be stale here.
Here, the "this" pointer is to a const class of foo. In this case, the
field "value" needs to be updated on first reference because it is a
cached value. If all of the values for bar's fields were loaded before the
call, it would be stale after the call.
You may argue the coercing constness away is a bad practice; however, the
language permits it and it is really good code like in the above example.
Here, the interface says that it is retrieving a value. The caller merely
perceives that it is reading a value and not writing into the object. It
is merely a coincidence of implementation that the body requires a
calculation for the value in cache.
Therefore, a good optimizer should probably rely on data flow analysis to
see if a variable is really constant.
Return to the
Search the comp.compilers archives again.