【发布时间】:2015-05-24 16:38:39
【问题描述】:
当我试图编译这段代码时,它显示错误:
main.cpp:19:3: error: invalid operands of types 'void' and 'int' to binary 'operator!='
这是文件:
#include <iostream>
#include <cstdio>
using namespace std;
#define $ DEBUG
#define DEBUG 1
#define _(out) do{ std::cout << __FILE__ << ":" << __LINE__ \
<< " " << out << '\n';}while(0)
#define _(out) printf(out);
int main(){
#ifdef LOCAL_PROJECT
#define DEBUG 0
#endif
$ && ({
_("eeeeewe");
});//line 19
return 0;
}
$ 是DEBUG 的简单名称,在运行时它是0 或1。
编译错误是针对这个源文件的。 如何摆脱这个并编译?
【问题讨论】:
-
@UmNyobe “简单” c++ 程序。 (你不能争论它是 C++)
-
@UmNyobe 我做错了什么?
-
一切。不要使用宏。
-
@Puppy 好的,我可以做到
debug && printf('1');,debug是布尔值。但是当我需要更多表达时,不仅仅是printf,该怎么办? -
这不是你真正的程序,是吗?错误信息和代码不匹配。
标签: c++ logging macros gcc-extensions