C extension=> pow(2, 1) gives DIFFERENT answers in different parts of C extension!?!?! Any ideas why?

Christian Seberino seberino at spawar.navy.mil
Thu Feb 5 05:36:11 CET 2004


Jeff

I can't tell you how glad I am for your post.  Your hunch
was EXACTLY right.

Chris


Jeff Epler <jepler at unpythonic.net> wrote in message news:<mailman.1122.1075727212.12720.python-list at python.org>...
> This may be a simple "C" error.  If you call pow() without a prototype
> in scope, a compiler will not necessarily give you an error.  However,
> the return type of pow() will be int, not double.  In that case,
> anything can happen.
> 
> $ cat seberino.c
> #ifdef RIGHT
> #include <math.h>
> #endif
> 
> #include <stdio.h>
> 
> int main(void) { printf("%f\n", pow(2, 1)); }
> $ gcc seberino.c -lm && ./a.out
> -1.993340
> $ gcc seberino.c -lm -DRIGHT && ./a.out
> 2.000000
> 
> You might consider enabling more compiler warnings:
> $ gcc -Wall seberino.c -lm
> seberino.c: In function `main':
> seberino.c:7: warning: implicit declaration of function `pow'
> seberino.c:7: warning: double format, different type arg (arg 2)
> seberino.c:7: warning: control reaches end of non-void function
> 
> Jeff



More information about the Python-list mailing list