2016-11-23 51 views
1

我得到这个奇怪的错误...gcc的错误:[枚举]字段声明为函数

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; 

任何想法上什么可能导致这个问题?

回答

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为您的字段名。

+0

就是这样!谢谢! –