我正在写一个简单的解析器读取配置文件。该接口的config.h只有三个 他们在简略如下主要功能,Ç命名建议
config_init();
config_dinit();
config_parse();
config_read_value();
我的问题是这些功能将发射不同类型的错误,对于一个示例,
config_init() emit , FILE_NOT_FOUND,FILE_EOF_ERROR,FILE_OPEN_ERROR, ...
config_dinit() emit , NOT_INIT_ERROR ,
config_parse() emit , PARSE_ERROR, OVERFLOW_ERROR, INVALID_CHARACTER_FOUND_ERROR,...
config_read_value() emit, SECTION_NOT_FOUND,KEYWORD_NOT_FOUND,OVERFLOW_ERROR,NOT_INITIALIZED_ERROR,INVALID_STATE_ERROR,... etc.
Then I create enums for each function, for by using these names ,
enum Config_ParseError{...} , enum Config_InitError{...} ,enum Config_ReadValueError{..}
etc.
一些枚举值相互重叠并点击“编译器错误”过。像 溢出错误,
我打开您的建议,
,我已经做了谷歌的快速调研,发现最流行的IRC客户端 源代码已经定义了这样的枚举,
enum {
CMDERR_OPTION_UNKNOWN = -3, /* unknown -option */
CMDERR_OPTION_AMBIGUOUS = -2, /* ambiguous -option */
CMDERR_OPTION_ARG_MISSING = -1, /* argument missing for -option */
CMDERR_UNKNOWN, /* unknown command */
CMDERR_AMBIGUOUS, /* ambiguous command */
CMDERR_ERRNO, /* get the error from errno */
CMDERR_NOT_ENOUGH_PARAMS, /* not enough parameters given */
CMDERR_NOT_CONNECTED, /* not connected to server */
CMDERR_NOT_JOINED, /* not joined to any channels in this window */
CMDERR_CHAN_NOT_FOUND, /* channel not found */
CMDERR_CHAN_NOT_SYNCED, /* channel not fully synchronized yet */
CMDERR_ILLEGAL_PROTO, /* requires different chat protocol than the active server */
CMDERR_NOT_GOOD_IDEA, /* not good idea to do, -yes overrides this */
CMDERR_INVALID_TIME, /* invalid time specification */
CMDERR_INVALID_CHARSET, /* invalid charset specification */
CMDERR_EVAL_MAX_RECURSE, /* eval hit recursion limit */
CMDERR_PROGRAM_NOT_FOUND /* program not found */
};
它定义的enum没有任何名称,那是一个很好的风格吗?那么为什么 那个原因是什么呢?
严重需要一些更好的命名决定。请不要伤害我我只是 开始阅读“写美丽的C代码”一书。
在此先感谢。 Sandun。
哇好建议标题先生, – 2011-06-09 13:30:11
'类型定义枚举_config_error error_t;'为我工作。 – Danijel 2017-04-07 07:06:11