Why does gcc report "implicit declaration of function ‘round’"?

c, compiler-warnings, gcc

Solution

I see you're using gcc.

By default, gcc uses a standard similar to C89. You may want to "force" it to use the C99 standard (the parts it complies with)

gcc -std=c99 -pedantic ...

Quote from GCC Manual

By default, GCC provides some extensions to the C language that on rare occasions conflict with the C standard. See Extensions to the C Language Family. Use of the -std options listed above will disable these extensions where they conflict with the C standard version selected. You may also select an extended version of the C language explicitly with -std=gnu89 (for C89 with GNU extensions) or -std=gnu99 (for C99 with GNU extensions). The default, if no C language dialect options are given, is -std=gnu89; this will change to -std=gnu99 in some future release when the C99 support is complete. Some features that are part of the C99 standard are accepted as extensions in C89 mode.

Problem

I have the following C code: ``` #include <math.h> int main(int argc, char ** argv) { double mydouble = 100.0; double whatever = round(mydouble); return (int) whatever; } ``` When I compile this, I get the warnings: ``` round_test.c: In function ‘main’: round_test.c:6: warning: implicit declaration of function ‘round’ round_test.c:6: warning: incompatible implicit declaration of built-in function ‘round’ ``` I'm rusty with C, but I thought that the #include brought a declaration for round() into scope. I've checked my ANSI standard (C99 is the only copy I have) which confirms that the round() function exists in the math.h header. What am I missing here? Edit: The compiler is GCC 4.3.2 on Ubuntu (intrepid, IIRC). Running gcc -E gives: ``` $ gcc -E round_test.c | grep round # 1 "round_test.c" # 1 "round_test.c" # 2 "round_test.c" 2 double whatever = round(mydouble); ``` so the definition obviously isn't being found in the headers.

Original source