each undeclared identifier is reported only once for each function it appears in

 提示错误:

‘EEXIST’ undeclared (first use in this function)

each undeclared identifier is reported only once for each function it appears in

意思是:对于每个出现在其中的函数,每个未声明的标识符只报告一次

按照我们正常做法,肯定是添加头文件。

但是在这个代码中,并不是 ‘EEXIST’ undeclared (first use in this function) 它的问题。

原本出错的代码:

#include 
#include 
#include 
#include 

//int mkfifo(const char *pathname, mode_t mode);

int main()
{
        if(mkfifo("./file",0600) == -1 && error != EEXIST){
                printf("creat file fail\n");
                perror("why");
        }

        return 0;
}

 根据这个错误提示,明显就应该做的是,添加头文件。但是,实际上我的头文件已经是添加好的了。所以没点眼力见压根开始找不到出错的原因在哪里

最后,是将代码中的 error != EEXIST  改成了 errno != EEXIST  ,其实就是代码写错了,把错误码写成了错误error。完美,编译成功。成功创建了命名管道 file 文件

总之一句:细节还是细节。

改正后的代码:

#include 
#include 
#include 
#include 

//int mkfifo(const char *pathname, mode_t mode);

int main()
{
        if(mkfifo("./file",0600) == -1 && errno != EEXIST){
                printf("mkfifo fail\n");
                perror("why");
        }


        return 0;
}

 

你可能感兴趣的:(#,3.进程间通信_IPC,疑难随笔,c语言,linux)