an error and a warning
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.)
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 testworks perfectly. Getting exact same results as those illustrated.
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).
Login