(972) uname -a
FreeBSD gadoid.ices.cmu.edu 5.2.1-RELEASE FreeBSD 5.2.1-RELEASE #0: Mon Feb 23
20:45:55 GMT 2004     [EMAIL PROTECTED]:/usr/obj/usr/src/sys/GENERIC 
i386
(973) cat a.c
#include <stdlib.h>
#include <stdio.h>

int main(int argc,char *argv[])
{
  float n = 40;
  int i;

  for (i = 0;i < 10;i++)
    foo();

  printf("%g\n",n + 2.0);
  return 0;
}

float foo()
{
  return 1.0;
}
(974) gcc a.c -o a
a.c:17: warning: type mismatch with previous implicit declaration
a.c:10: warning: previous implicit declaration of `foo'
a.c:17: warning: `foo' was previously implicitly declared to return `int'
(975) ./a
nan
(976) 

The above program is missing a prototype for the "foo" function.  This
correctly causes a warning, but the missing prototype causes problems for
completely unrelated code.  In the above example, the foo() function is called
10 times, then an unrelated floating point operation is peformed which
incorrectly results in a "nan".  Note that if the number of loop iterations is
reduced to 6 or fewer times, the program will print the correct result.


-- 
           Summary: missing prototype causes strange effect at a distance
                    with float.
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hansen at cmu dot edu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24971

Reply via email to