我知道,在C语言中,将数字常量声明为enum
而不是#define
是非常惯用的,或者至少是很好的风格.
/* bad style */
#define MAXLINE 1024
/* good/better style */
enum {
MAX_LINE = 1024
};
是否有定义字符串常量的等价规则?
/* is this good style? */
#define HELLO "Hello World"
/* or is this better? */
const char *HELLO2 = "Howdy";
倾向于什么?如果可能的话,说明这两种方法的一些缺点.