On Tue, Apr 11, 2006 at 11:07:35PM +0000, Jonathan Herriott wrote:
> Question then.  Why would it work when I don't use variables if I
> don't include the library?  This question is just out of curiosity.

Because the compiler recognizes that pow() when called with only 
constants as arguments can be calculated at compile-time and does so.

If you look at the generated assembler you will see that there is no 
call to pow() actually being made there -- it has been replaced by
the appropriate constant.


> 
> 
> On 4/11/06, Nicolas Blais <[EMAIL PROTECTED]> wrote:
> > 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.
> >



-- 
<Insert your favourite quote here.>
Erik Trulsson
[EMAIL PROTECTED]
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to