errno - 添加到“my_header.h”会导致错误消息
问题描述
我正在尝试从errno.h
my_func 中打印“错误号”。如果我<errno.h>
直接包含在 my_func.c 中,一切正常。但是如果我包含<errno.h>
在"my_header.h"
然后包含"my_header.h"
在 my_func.c 编译器会吐出错误:
src/my_func.c: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'int (*(*)())' [-Wint-conversion] return (print_errno(errno));
/usr/include/sys/errno.h:81:15: note: expanded from macro 'errno' #define errno (*__error())
my_func.c:
#include "my_header.h"
int my_func(void)
{
if (write(5, "Hello, world!", 13) == -1)
return(print_errno(errno));
}
my_header.h:
#include <errno.h>
int print_errno(int errno);
print_errno.c:
#include "my_header.h"
#include <stdio.h>
int print_errno(int errno)
{
printf("error number = %d", errno);
return (-1);
}
为什么我有这个错误?
解决方案
这是因为您已经命名errno
了由预处理器扩展的参数,因为这个
#define errno (*__error())
(错误号.h)
所以这个原型
int print_errno(int errno);
扩展到
int print_errno(int (*__error()));
简短的修复,不要调用你的参数errno
推荐阅读
- ios - y位置的UITableView内容偏移量总是返回0
- node.js - 节点:向 TCP 服务器发送确认的数据
- python - 用户定义索引处空格之间的 Python 子字符串
- python - 在带有附件的python中发送邮件多次发送
- mysql - 搜索字符串时只考虑初始数字
- java - 将对象列表转换为 Json 字符串时发生 Stackoverflow 错误
- sublimetext3 - 如何在 Sublime 中将 Ab 批量替换为 A('b')?
- php - 根据另一张表上的数据更新一张表
- spring-boot - 映射表所需的Spring Boot域类
- spring - Spring Boot:测试自定义 MongoTemplate 转换器