I wrote a function that prints text on standard output. At compilation (using gcc exemple.c
), i get a warning : implicit declaration of function 'write'
. Here is an exemple :
exemple.c :
#include <unistd.h>
int main(void){
write(1, "Hello World !", 13);
return (0);
}
Output :
exemple.c: In function ‘main’:
exemple.c:4:2: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
write(1, "Hello World !", 13);
I included the unistd.h
header, that's why i don't understand the reason of the warning.
I managed to "fix" the warning by adding
#include <sys/types.h>
//The real prototype, from unistd.h
extern ssize_t write(int __fd, void *__buf, size_t __n)__wur;
But this tells me it may be a bad idea.
Shouldn't the unistd.h
be enought like in these exemples ? Or is there a better way to use/compile write
?
Note : I'm compiling with the gcc 5.3.1
Edit : Here is the link to the .i
file created by running gcc exemple.c -save-temps
: exemple.i