Warning: implicit declaration of function ‘read’ ('write')

Hello.

Please tell me why the compiler throws warning when using read and write?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
...
n = read(newsockfd, &buffer, (size_t *) tmp_size);
...
n = write(newsockfd, "Hi!", (size_t *) 3);
...

gcc -Wall -o "server" "server.c"
server.c: In function ‘main’:
server.c:74:5: warning: implicit declaration of function ‘read’ [-Wimplicit-function-declaration]
server.c:85:5: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
Compilation finished successfully.

From the translation, it is clear that an implicit function declaration occurred. It turns out that I'm missing some kind of include?

Author: DEN, 2013-04-19

1 answers

This is a feature from the compiler. It can ignore the fact that there is no prototype, but if it finds a suitable symbol when linking, it will link everything. But whether it will work is not known, since the prototype is unknown and an emergency with the stack may occur. In this case, you need to add #include <unistd.h>

 10
Author: KoVadim, 2013-04-19 19:17:13