pow function working unexpectedly

Andy Reitz reitz at eecs.cwru.edu
Tue Apr 11 23:13:11 UTC 2006


On Tue, 11 Apr 2006, Jonathan Herriott wrote:

> Question then.  Why would it work when I don't use variables if I
> don't include the library?  This question is just out of curiosity.

That's a pretty good question. In the case where we have pow(x,y), I see
this:

areitz at bottom[~/src]$ gcc -c pow_test.c
areitz at bottom[~/src]$ nm pow_test.o
00000000 T main
         U pow
         U printf

In the case where it is pow(2,3), I see this:

areitz at bottom[~/src]$ gcc -c pow_test.c
areitz at bottom[~/src]$ nm pow_test.o
00000000 T main
         U printf

So, clearly, something is optimizing the pow() function away when the
arguments are hard-coded lvalues, instead of varibles.

Now, what that thing *is*, I don't know.

-Andy.


More information about the freebsd-questions mailing list