This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: std::pow implementation
- From: Martin Reinecke <martin at MPA-Garching dot MPG dot DE>
- To: gdr at integrable-solutions dot net
- Cc: gcc at gcc dot gnu dot org
- Date: Thu, 31 Jul 2003 11:11:19 +0200
- Subject: Re: std::pow implementation
- Organization: Max-Planck-Institut fuer Astrophysik
Gabriel Dos Reis wrote:
It is tempting to make the analogy with "register", but you have to
acknowledge the fact that inlining strategy is not at the same level
of sophistication as register allocation. Therefore, any answer you
get for the question above is irrelevant to whether you should decide
whether your programmed inliner always knows better than the
programmer. Until then, please listen to the programmer. Don't
transmute "inline".
Yes, you should listen to the programmer. But unless the programmer
has a chance to express his intent _exactly_, there is no way to find
out what he really meant. And he cannot do so in the discussed situation.
When writing a member function, the programmer has to adress the question
"Should this function be inlined?", and you agreed that there are three
valid answers: "yes", "no", and "it depends; let the compiler decide".
But current g++ only allows two ansers:
"yes" (i.e. make the function inline), and
"no" (i.e. define the function in some .cc file)
If the programmer can only choose two of three alternatives, it is not
possible to determine whether he didn't actually want to say "it depends".
If he says "no", he most certainly means "no", because then g++ has not much
chance of inlining the function if it's not defined in the current translation
unit.
But if he says "yes", how can you be sure he really meant "yes" and not
"it depends"? The language practically forces him to lie, and therefore
you can't trust him blindly.
My opinion is that if the programmer says "yes", the only thing you can be sure
about is that he didn't mean "no", but that's not enough to determine whether
g++ should unconditionally inline or not.
Of course, this argument breaks down if there is some way to say "it depends".
I don't know of any. If there is, please show me!
Martin