This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: help understanding a gcc compilation issue


Gabi Voiculescu <boy3dfx2@yahoo.com> writes:

> When running, the function llrint() using and returning 64 bit variables fails to call rint(), and instead calls itself!?!.
>
> #include <stdio.h>
> extern double rint(double x);
>
> long long llrint(double x);
> long long llrint(double x)
> {
> printf("%s,%d llrint entry\n", __func__, __LINE__); //-gabi 07/08/2009 
>     return (long long) rint(x);
> }
>
> When calling llrint I see the print statement repeated forever, without calling rint() or returning from llrint().

gcc is outsmarting itself.  When it sees "(long long) rint(x)", it
converts that into "llrint(x)".  This is normally a safe conversion, but
of course it is unsafe when you are trying to implement llrint itself.
You can avoid this problem by using the -fno-builtin-rint option.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]