This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: help understanding a gcc compilation issue
- From: Ian Lance Taylor <iant at google dot com>
- To: Gabi Voiculescu <boy3dfx2 at yahoo dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 08 Jul 2009 21:42:35 -0700
- Subject: Re: help understanding a gcc compilation issue
- References: <718019.89604.qm@web37001.mail.mud.yahoo.com>
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