I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
Index »

an error and a warning

tiborh\′s Photo
10 Jan 09, 8:54PM
(2 replies)
an error and a warning
Has anyone actually tried to compile the example code above? Well, I tried and here's what came out:

round_codecogs.c: In function 'main': round_codecogs.c:6: error: 'for' loop initial declaration used outside C99 mode round_codecogs.c:7: warning: incompatible implicit declaration of built-in function 'round'

(using (in Kubuntu 8.10): gcc -lm -o <progname> <progname>.c)

The error is easy to solve: the variable "a" should not be defined inside the "for" loop. But I have no idea how one can make the warning disappear. (Of course, I can modify the problem line:

printf("round of %.1lf is %d\n", a, (int)(a+0.5));

to avoid the problem.)
john\′s Photo
11 Jan 09, 11:07PM
Hi, just tried myself under OSX. With gcc, I get errors also.

But isn't gcc for compiling straight c, not c++. So try use: g++, thus:
g++ test.cpp -lm -o test
works perfectly. Getting exact same results as those illustrated.
tiborh\′s Photo
11 Jan 09, 11:35PM
Yes, you're right. It works very well with g++. I just did not realise that the code snippet was meant to be c++ and not c (in which I was working when I checked on this function).
Currently you need to be logged in to leave a message.