嗨,我在一个日志系统上,想要创建一个保存记录器内部状态的结构:
#include "logger.h"
#include "main.h"
/*
* Variables
*/
/*State of Logging*/
struct {
bool logOn;
static enum eLogLevel outputLevel[7];
} sLogStruct;
static struct sLogStruct gLogData;
void Log(enum eLogSubSystem sys, enum eLogLevel level, char * msg)
{
}
我在 logger.h 文件中定义了 eLogLevel 枚举:
#ifndef LOGGER_H_
#define LOGGER_H_
#include "globaldefinitions.h"
/*
* Logger data types
*/
typedef enum eLogLevel {none, information_only, debugging, warning, error, critical};
typedef enum eLogSubSystem {coresystem, heartrate, temperature, accelerometer, communication, flash, firmwareUpdate};
/*
* Public functions
*/
void Log(enum eLogSubSystem sys, enum eLogLevel level, char * msg);
void LogWithNum(enum eLogSubSystem sys, enum eLogLevel level, char * msg, int number);
void LogSetOutputLevel(enum eLogSubSystem sys, enum eLogLevel level);
void LogGlobalOn(void);
void LogGlobalOff(void);
void LogVersion (em_fw_version_t version);
#endif /* LOGGER_H_ */
但是,我的编译器提示:
../Logging/logger.c:18:2: error: expected specifier-qualifier-list before 'static'
static enum eLogLevel outputLevel[7];
我不知道如何解决这个问题,我猜它很简单,但我不知道为什么它不接受 logger.h 文件中的 typedef 枚举 eLogLevel。 你能帮我理解一下吗?
最佳答案
您的原始代码存在不同的问题。
- 在 C 语言中,
struct
的成员不能是静态的。如果需要,请使用 C++ 您的
typedef
不正确。他们应该写:typedef enum {none, information_only, debugging, warning, error, critical} eLogLevel ;
和
struct { bool logOn; eLogLevel outputLevel[7]; } sLogStruct;
或
typedef struct { bool logOn; eLogLevel outputLevel[7]; } SLogStruct; SLogStruct sLogStruct;
关于c - 如何在我的结构中使用类型定义的枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39513811/