Andreas Naumann wrote:
> Hi,
> 
> it is an interesting problem. If you tell the gcc to use the math library,
> it works. The interesting thing is the way of testing.
> 
> The cmake macro simply declares a function foo with the signature
>     char foo();
> and call this one without arguments. If you tell cmake to link against the
> math library, it works.
> 
> But, if you simply call sqrt(5.0) the library is ommitted (I think the gcc
> optimizes the code?)

As it also does with e.g. strlen("something"). Functions that are marked to 
return the same value if the same value is passed in and which are used with a 
constant input are calculated during compilation and the result is used in the 
binary. So if you write something like:

if (sqrt(strlen("foobar")) > 4)
  return 1;
else
  return 0;

I'm rather sure the code generated by gcc (if optimizations are turned on) 
will be just "return 0".

Eike
-- 

Attachment: signature.asc
Description: This is a digitally signed message part.

--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to