Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Apr 2006 22:54:18 +0000
From:      "Jonathan Herriott" <herriojr@gmail.com>
To:        freebsd-questions@freebsd.org
Subject:   pow function working unexpectedly
Message-ID:  <6a56d69c0604111554o587ce2c5ha1ff4ea20bbab0a4@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
I just want to make sure I'm not being stupid before I send in a bug.=20
The problem seems to be with gcc when using the pow function in the
math.h library.  Here's code that works:

#include <stdio.h>
#include <math.h>

int main()
{
     printf("%f\n", pow(2,3));
     return 0;
}


Now, the following will not compile:

#include <stdio.h>
#include <math.h>

int main()
{
     int x =3D 2; // I tried these as doubles too since the pow function
takes doubles
     int y =3D 3;

     printf("%f\n", pow(x,y));
     return 0;
}

I compiled both programs using:
gcc test.c

The second example gives the following error:
/var/tmp//ccxtkMwv.o(.text+0x45): In function `main':
: undefined reference to `pow'

If I comile with g++, I have no issues.  Are these results that I
should have?  If so, why?  If not, I'm going to submit the bug on gcc
(or the linker, but I'm guessing it's the same group).

Thanks,
Jonathan Herriott



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6a56d69c0604111554o587ce2c5ha1ff4ea20bbab0a4>