【发布时间】:2013-09-28 06:54:49
【问题描述】:
我使用gcc编译的代码
#include<stdio.h>
#include<stdbool.h>
#define true 9
int main() {
printf("TRUE = %d\n",true);
return 0;
}
我得到错误
test.c:3:0: warning: "true" redefined [enabled by default]
In file included from test.c:2:0:
/usr/lib/gcc/x86_64-linux-gnu/4.7/include/stdbool.h:34:0: note: this is the location of the previous definition
但是当我稍微修改一下代码时
#include<stdio.h>
#define true 9
#include<stdbool.h>
int main() {
printf("TRUE = %d\n",true);
return 0;
}
输出:
TRUE = 1
问题:
我理解第一种情况下出错的原因,但在第二种情况下,当我在#include<stdbool.h> 之前定义true 时,为什么允许重新定义true?
更新:
这里是stdbool.h。
前几行是
#ifndef _STDBOOL_H
#define _STDBOOL_H
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
这和于浩的answer完全不同。
【问题讨论】:
-
我希望你没有认真考虑定义真实
-
@Bathsheba 我认为 OP 正在做一个测试,所以他需要一个不同于
1的值来查看哪个宏在工作。
标签: c gcc include c-preprocessor