警告:内置函数'printf'的不兼容隐式声明[默认启用]

40 c system-calls

我正在使用以下C代码:

#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>

int main()
{
    int file=0;
    if((file=open("testfile.txt",O_RDONLY)) < -1)
            return 1;
    char buffer[19];
    if(read(file,buffer,19) != 19)  return 1;
    printf("%s\n",buffer);

    if(lseek(file,10,SEEK_SET) < 0) return 1;

    if(read(file,buffer,19) != 19)  return 1;
    printf("%s\n",buffer);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译后会产生警告:

warning: incompatible implicit declaration of built-in 
function ‘printf’ [enabled by default]
Run Code Online (Sandbox Code Playgroud)

它是什么意思,我如何安抚C编译器不引发警告?

Kar*_*ara 84

您需要添加#include <stdio.h>到文件的顶部.

  • @rkioji,因为编译器可以猜测函数的定义,并且可以很好地猜测stdio.h中存在的函数 (4认同)