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 <sys/types.h>
#include <sys/stat.h>
#include <error.h>
#include <stdio.h>

//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 <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>

//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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

枕上

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值