gcc report : incompatible implicit declaration of built-in function ‘round’

I have a simple C program with use round function. This is my simple code (save as main.c) :

When I compile this code with command :

gcc main.c -lm -o tesround

I get this warning :

warning: incompatible implicit declaration of built-in function ‘round’

When I read GCC manual, I get this information :

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.

We can solve this problem  ( warning: incompatible implicit declaration of built-in function ‘round’ ) with add FLAGS -std=c99 when compile this code. So, new command to compile this code become :

gcc main.c -lm -o tesround -std=c99

Or we can create our function to replace round function in math.h. Create new function with name roundfunc to replace round function. So, our code become :

Compile this code with command :

gcc main.c -lm -o tesround -std=c99

This is output from compared our round function with C round function :

This is a simple method how to solve warning warning: incompatible implicit declaration of built-in function ‘round’ when use round function in C. We can use -std=c99 when compile our code or create our function to replace round function.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.