科恩给出了“扩展到表达式中没有”与定义的符号
问题描述:
我试图用coan,产生一个干净版本的代码库,但它creashes上的第一个定义的第一源代码精细,使用:科恩给出了“扩展到表达式中没有”与定义的符号
coan source -DNON_SMS --filter c,h --recurse --replace test -V
我得到:
coan: progress 0x00101: Processing file (1)
"D:\Documents\Downloads\test\cli.c"
coan: D:\Documents\Downloads\test\cli.c: line 53: error 0x00816: "NON_SMS" expands to nothing within expression, in "#if (NON_SMS) /* Non-SMS compile */"
coan: progress 0x02101: Completed with errors, exit code 0x04
coan: info 0x02201: 1 out of 41 input files were reached; 40 files were not reached
coan: info 0x02202: 0 out of 1 files reached were valid; 1 were abandoned due to parse errors
但代码上正常工作MSVS及本声明其实很简单:
#if (NON_SMS) /* Non-SMS compile */
#include <stdlib.h> /* Standard library definitions */
#include <string.h> /* String related definitions */
#else
这是在Windows 7 x64上。
答
科恩预计,当代码是这样
#if (MACRO)
是MACRO
将有一个价值 - 如果你只是想测试宏是否被定义,你会写
#ifdef MACRO
所以你需要给NON_SMS
一个值,例如
coan source -DNON_SMS=1 --filter c,h --recurse --replace test -V
+0
在gcc和其他常见编译器中,'-DNON_SMS'实际上表示为'-DNON_SMS = 1'。我不知道任何关于“coan”的内容,但是如果它给“-D”赋予微妙不同的含义,那么这对用户来说有点混乱。 –
+0
@ M.M好的一点,它似乎被视为“-DNON_SMS =' – Barmar
这是C还是C++?语言之间有区别。例如,C++有'std :: string',而C没有。在C中,我可以有一个名为“class”的变量。相应地调整你的标签。 –
@ThomasMatthews这是既适用于C和C++作为coan过程都具有相同的接口。 – canesin
尝试使用'-DNON_SMS = 1'或'-DNON_SMS = 0'。代码正在检查值,而不仅仅是它是否被定义。 – Barmar