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 :

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#define roundfunc(x) ((int)((x)>0.0?(x)+0.5:(x)-0.5))

intmain(intargc,char**argv)

{

floata,b;

intc,d;

a=5.6;

b=5.3;

// METHOD I

c=round(a);

d=round(b);

printf("METHOD I \n");

printf("a=%2.2f , round = %i \n",a,c);

printf("b=%2.2f , round = %i \n",b,d);

// METHOD II

c=roundfunc(a);

d=roundfunc(b);

printf("METHOD II \n");

printf("a=%2.2f , round = %i \n",a,c);

printf("b=%2.2f , round = %i \n",b,d);

return(1);

}

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 :

1

2

3

4

5

6

METHODI

a=5.60,round=6

b=5.30,round=5

METHOD II

a=5.60,round=6

b=5.30,round=5

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.