【发布时间】:2014-03-26 19:18:18
【问题描述】:
有时我会看到 define 预处理器,但没有分配给它的值。例如:
#define VAR
当没有指定值时,分配给VAR的是什么?
我也在读一段文字,我看到了:
#ifndef ERROR_FUNCTIONS_H
#define ERROR_FUNCTIONS_H
/* Error diagnostic routines */
void errMsg(const char *format, ...);
#ifdef __GNUC__
/* This macro stops 'gcc -Wall' complaining that "control reaches
end of non-void function" if we use the following functions to
terminate main() or some other non-void function. */
#define NORETURN __attribute__ ((__noreturn__))
#else
#define NORETURN
#endif
ERROR_FUNCTIONS_H 是头文件吗?或者这只是define 预处理器定义的常量?
【问题讨论】:
-
#define VAR有一个空字符串作为其替换值。可以测试是否设置。如果它出现在defined(或#ifdef或#ifndef)以外的上下文中,则它将被替换为空。NORETURN宏是一个示例,说明当编译器不是 GCC(或不声称是 GCC——注意clang)时,替换文本什么都不是。
标签: c c-preprocessor