Gcc Error: [enum] field declared as a function
Gcc Error: [enum] field declared as a function
我遇到了这个奇怪的错误...
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;
关于可能导致问题的原因有什么想法吗?
翻译单元包含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>
,
没有错误。
除非您在发布诊断时打错了字,否则这会建议
您的 <errno.h>
导入定义:
#define errno (*_errno ())
解决方案是不要使用 errno
作为您的字段名称。
我遇到了这个奇怪的错误...
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;
关于可能导致问题的原因有什么想法吗?
翻译单元包含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>
,
没有错误。
除非您在发布诊断时打错了字,否则这会建议
您的 <errno.h>
导入定义:
#define errno (*_errno ())
解决方案是不要使用 errno
作为您的字段名称。