尝试在antoher中包含一个头文件的枚举时,我一直遇到问题。我正在使用的环境是使用IAR Embedded Workbench的嵌入式C。
我有一个名为“ enums.h”的专用枚举类型的头文件。
#ifndef ENUMS_H_
#define ENUMS_H_
typedef enum
{
SET,
SCHEDULE,
EXECUTE
}action_type_t;
#endif
还有一个名为“ parser.h”的解析器的头文件
#ifndef PARSER_H_
#define PARSER_H_
#include "enums.h"
#include <stdint.h>
typedef struct
{
action_type_t action;
uint16_t nbytes;
}Message;
#endif
在parser.c中,我将标头包括为
#include "parser.h"
编译此文件时,出现错误“标识符action_type_t未定义”
我在这里做错了什么?在这一点上,我很沮丧。
谢谢
您的enum
定义缺少逗号,在没有包含的情况下parser.h
使用uint16_t
,<stdint.h>
并且(更多余的是,)您的include Guard宏侵犯了保留的命名空间,因为它以_
和大写字母开头。
这应该工作:
enums.h:
#ifndef ENUMS_H_
#define ENUMS_H_
typedef enum
{
SET,
SCHEDULE,
EXECUTE, /*the last comma is optional*/
}action_type_t;
#endif
parser.h:
#ifndef PARSER_H_
#define PARSER_H_
#include "enums.h"
#include <stdint.h>
typedef struct
{
action_type_t action;
uint16_t nbytes;
}Message;
#endif
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句