我试图在errno.h中用my_func打印“错误号”。如果我将<errno.h>直接包含在my_func.c中,一切都会好起来的。但是,如果我在"my_header.h"中包括<errno.h>,然后在my_func.c编译器中包含"my_header.h",则会产生错误:
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);
}为什么我有这个错误?
发布于 2019-01-21 16:18:05
这是因为您已经将参数errno命名为由预处理器展开的参数,因为这是
#define errno (*__error())(errno.h)
所以这个原型
int print_errno(int errno);扩展到
int print_errno(int (*__error()));短期修复,不要调用参数errno
https://stackoverflow.com/questions/54293641
复制相似问题