【问题标题】:Gcc Error: [enum] field declared as a functionGcc 错误:[enum] 字段声明为函数
【发布时间】:2016-11-23 19:11:59
【问题描述】:
我遇到了这个奇怪的错误...
jos_log.c:16:13: error: field '_errno' declared as a function
ERRNO errno;
^
...当我编译这段代码时:
typedef enum ERRNO_
{
/* ... */
}
ERRNO;
typedef struct LOG_ENTRY_
{
char * message;
ERRNO errno; // <--- Error here
ERR_SEV severity;
}
LOG_ENTRY;
关于什么可能导致问题的任何想法?
【问题讨论】:
标签:
gcc
struct
enums
compiler-errors
c11
【解决方案1】:
翻译单元包括errno.h,通过errno已经
定义为预处理器宏,其定义引发错误。
在我的情况下,使用gcc (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1,文件:
#include <errno.h>
typedef int ERR_SEV;
typedef enum ERRNO_
{
x
}
ERRNO;
typedef struct LOG_ENTRY_
{
char * message;
ERRNO errno;
ERR_SEV severity;
}
LOG_ENTRY;
产生类似的错误:
a.c:12:13: error: field ‘__errno_location’ declared as a function
ERRNO errno;
^
由于:
# define errno (*__errno_location ())
在<bits/errno.h> 内,在<errno.h> 内。没有#include <errno.h>,
没有错误。
除非您在发布 disgnostic 时打错字,否则建议
你的 <errno.h> 导入定义:
#define errno (*_errno ())
解决方案是不要使用errno 作为您的字段名称。