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

2006-02-14 Thread Thomas Jollans
On Tuesday 14 February 2006 11:48, Oliver Elphick wrote:
 [snip]
   sprintf(tmp, %.4f, round((double) newqty * price * discpc) / 100.);
 [snip]
 orderimpl.cpp:84: implicit declaration of function `int round(...)'

this is indeed wierd. %.4f should expect a double, not an int. You could try 
%.4g or %.4e or ask in comp.lang.c++ or comp.lang.c in USENET..

thomas


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



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

2006-02-14 Thread Jan C. Nordholz
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.


HTH,

Jan

-- 
Jan C. Nordholz
jckn At gmx net


signature.asc
Description: Digital signature


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

2006-02-14 Thread Oliver Elphick
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.)

-- 
Oliver Elphick  olly@lfix.co.uk
Isle of Wight  http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA  92C8 39E7 280E 3631 3F0E  1EC0 5664 7A2F A543 10EA
 
   Do you want to know God?   http://www.lfix.co.uk/knowing_god.html


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



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

2006-02-14 Thread Jan C. Nordholz
Hi,

 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.)

you could use the features header. Start your source files with

#define _ISOC99_SOURCE
#include features.h

This will toggle the appropriate __USE_* macros (__USE_ISOC99, in this
case) that aren't set by the compiler. There are a few other macros you
might want to set (_POSIX_SOURCE, or even _GNU_SOURCE), so perhaps you
should have a closer look at features.h if you plan to use it directly.


Regards,

Jan
-- 
Jan C. Nordholz
jckn At gmx net


signature.asc
Description: Digital signature


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

2006-02-14 Thread Sergio Cuéllar Valdés
2006/2/14, Oliver Elphick olly@lfix.co.uk:
 I am trying to use the math function round() according to the manpage,
 but it does not compile.  Can anyone explain why not, please?
 The command line and error are:

 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(...)'


Hi,

hmmm, have you tried to add the -lm  ???

Cheers,
Sergio

---
http://biorobotics.fi-p.unam.mx
--
Meine Hoffnung soll mich leiten
Durch die Tage ohne Dich
Und die Liebe soll mich tragen
Wenn der Schmerz die Hoffnung bricht



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

2006-02-14 Thread Kevin B. McCarty
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 [EMAIL PROTECTED]   Physics Department
WWW: http://www.princeton.edu/~kmccarty/Princeton University
GPG: public key ID 4F83C751 Princeton, NJ 08544


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



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

2006-02-14 Thread Oliver Elphick
On Tue, 2006-02-14 at 15:15 +0100, Jan C. Nordholz wrote:
 Hi,
 
  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.)
 
 you could use the features header. Start your source files with
 
 #define _ISOC99_SOURCE
 #include features.h
 
 This will toggle the appropriate __USE_* macros (__USE_ISOC99, in this
 case) that aren't set by the compiler. There are a few other macros you
 might want to set (_POSIX_SOURCE, or even _GNU_SOURCE), so perhaps you
 should have a closer look at features.h if you plan to use it directly.

Thanks to you and others for that suggestion.

Defining _GNU_SOURCE fixes the problem for g++-2.95.

-- 
Oliver Elphick  olly@lfix.co.uk
Isle of Wight  http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA  92C8 39E7 280E 3631 3F0E  1EC0 5664 7A2F A543 10EA
 
   Do you want to know God?   http://www.lfix.co.uk/knowing_god.html


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



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

2006-02-14 Thread Matt Zagrabelny
On Tue, 2006-02-14 at 09:40 -0600, Sergio Cuéllar Valdés wrote:
 2006/2/14, Oliver Elphick olly@lfix.co.uk:
  I am trying to use the math function round() according to the manpage,
  but it does not compile.  Can anyone explain why not, please?
  The command line and error are:
 
  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(...)'
 
 
 Hi,
 
 hmmm, have you tried to add the -lm  ???

i was thinking the same, but it looks as though he is only compiling,
not linking, so one would think that '-lm' would have no impact.

-matt zagrabelny


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



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

2006-02-14 Thread Oliver Elphick
On Tue, 2006-02-14 at 10:54 -0600, Matt Zagrabelny wrote:
  hmmm, have you tried to add the -lm  ???
 
 i was thinking the same, but it looks as though he is only compiling,
 not linking, so one would think that '-lm' would have no impact.

That's right; the -c option was used.  This is just one module of many,
with the compilation of each module called from a makefile.

-- 
Oliver Elphick  olly@lfix.co.uk
Isle of Wight  http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA  92C8 39E7 280E 3631 3F0E  1EC0 5664 7A2F A543 10EA
 
   Do you want to know God?   http://www.lfix.co.uk/knowing_god.html


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]