keil for arm的#if RST==0 #else #endif中RST未定义居然不报错
keil for arm的#if RST==0
//程序1
#else
//程序2
#endif
RST未定义居然不报错,RST按照0处理了,这可真是危险哪。怎样才能让KEIL在这种情况下能报错? 楼主真不要随便怀疑这么成熟的编译器。
可以看看C语言条件编译与预处理方面的文章 binaimei2007 发表于 2014-3-3 17:27
楼主真不要随便怀疑这么成熟的编译器。
可以看看C语言条件编译与预处理方面的文章 ...
这个不是编译器的bug,而是C99里有明确的规定。没定义的都替换为0 Prior to evaluation, macro invocations in the list of preprocessing tokens that will become the controlling constant expression are replaced (except for those macro names modified bythe defined unaryoperator),justasinnormaltext.If thetoken defined is generated as a result of this replacement process or use of the defined unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined.After allreplacementsduetomacroexpansionandthe defined unary operator have been performed, all remaining identifiers are replaced with the pp-number 0, andtheneachpreprocessingtokenisconvertedintoatoken. 前面自己判断RST是否已定义 本帖最后由 leecny2012 于 2014-3-3 18:18 编辑
没有怀疑C编译器,只是想找到解决问题的方法。 leecny2012 发表于 2014-3-3 18:17
没有怀疑C编译器,只是想找到解决问题的方法。
多一个#ifdefRST ,这样就可以了 #if defined(RST) && (RST == 0)
...
页:
[1]