[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: C++: Math function round() does not compile - why?



Oliver Elphick wrote:

> On Tue, 2006-02-14 at 14:11 +0100, Jan C. Nordholz wrote:
>> Hi Oliver,
>> 
>> > g++-2.95 -c -pipe -DQWS -fexceptions -fno-rtti -Wall -W -g -std=c99 -I/opt/Qtopia/include -o orderimpl.o orderimpl.cpp
>> > orderimpl.cpp: In method `void OrderImpl::calculate_line(int)':
>> > orderimpl.cpp:84: implicit declaration of function `int round(...)'
>> 
>> this sounds like <math.h> doesn't give you the prototype for round().
>> Try to run <math.h> through the preprocessor alone
>> (g++-2.95 -std=c99 -E /usr/include/math.h), and grep for "round".
>> I don't get the definition with "g++-3.3" alone, but with
>> "g++-3.3 -std=c99" I do... YMMV. I've got no g++-2.95 here to continue
>> the tests.
> 
> with g++-2.95, this gives no prototypes for round().
> 
> So it appears that -std=c99 does not work. Is there some way to achieve
> this for 2.95?  (This is now academic, since I have written my own
> version for this application.)

Maybe try defining _ISOC99_SOURCE in your source code before #including
math.h?  (You might need to put the #define before _any_ #include
statement and maybe specifically #include features.h.)  For instance:

#define _ISOC99_SOURCE
#include <features.h>
#include <math.h>

If I've put together the clues correctly, setting this macro is
equivalent to the -std=c99 option.  See the comment at the top of
/usr/include/features.h (after the copyright blurb) for more information.

regards,

-- 
Kevin B. McCarty <kmccarty@princeton.edu>   Physics Department
WWW: http://www.princeton.edu/~kmccarty/    Princeton University
GPG: public key ID 4F83C751                 Princeton, NJ 08544



Reply to: