pow function working unexpectedly
Nicolas Blais
nb_root at videotron.ca
Tue Apr 11 22:57:50 UTC 2006
On Tuesday 11 April 2006 18:54, Jonathan Herriott wrote:
> I just want to make sure I'm not being stupid before I send in a bug.
> 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 = 2; // I tried these as doubles too since the pow function
> takes doubles
> int y = 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
gcc -lm test.c works. You forgot to include the math library.
--
FreeBSD 7.0-CURRENT #1: Sat Apr 8 21:33:25 EDT 2006
root at clk01a:/usr/obj/usr/src/sys/CLK01A
PGP? : http://www.clkroot.net/security/nb_root.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20060411/c701a681/attachment.pgp
More information about the freebsd-questions
mailing list