[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Re: Re: Implicition declarations of functions and bugs



Samuel Thibault, le Sat 11 Mar 2006 01:43:34 +0100, a écrit :
> > $ gcc-3.3 -c -g -O -Wall t.c
> > t.c: In function `foo':
> > t.c:4: warning: implicit declaration of function `strdup'
> > t.c:4: warning: return makes pointer from integer without a cast
> 
> Because strdup() here gets an implicit
> int strdup(int str)
> declaration, hence the warnings.
> 
> > gcc-4.0 -c -g -O -Wall t.c
> > t.c: In function 'foo':
> > t.c:4: warning: implicit declaration of function 'strdup'
> > t.c:4: warning: incompatible implicit declaration of built-in function 'strdup'
> 
> Same story, except that gcc has additionnal knowledge of which prototype
> the strdup function should have: char *strdup(const char *str); . And
> char * and int are not compatible types.

Another example:
int main(void) {
	return abs(-1);
}

$ gcc-3.3 test.c -o test -Wall
test.c: In function `main':
test.c:3: warning: implicit declaration of function `abs'
$ gcc-4.0 test.c -o test -Wall
test.c: In function 'main':
test.c:3: warning: implicit declaration of function 'abs'

Here gcc 4.0 doesn't complain so much, because even if the abs()
function was not declared, the implicit prototypes matches the actual
prototype of the built-in abs() function, hence no potential binary
break if the programmer is really using the libc's abs() function.

Regards,
Samuel



Reply to: