hue*_*ebe 52 c visual-c++
输入拼写错误后,编译并执行以下表达式(简化):
if((1 == 2) || 0 (-4 > 2))
printf("Hello");
Run Code Online (Sandbox Code Playgroud)
当然,0应该不存在.
为什么要编译,表达式是什么意思?
原始(简化)应如下所示:
if((1 == 2) || (-4 > 2))
printf("Hello");
Run Code Online (Sandbox Code Playgroud)
这没有编译:
if((1 == 2) || true (-4 > 2))
printf("Hello");
if((1 == 2) || 1 (-4 > 2))
printf("Hello");
if((1 == 2) || null (-4 > 2))
printf("Hello");
Run Code Online (Sandbox Code Playgroud)
Rup*_*Rup 26
看起来这是一个Visual C++扩展,支持一个特定的"无功能定义"的习惯用法.从警告C4353页面:
// C4353.cpp
// compile with: /W1
void MyPrintf(void){};
#define X 0
#if X
#define DBPRINT MyPrint
#else
#define DBPRINT 0 // C4353 expected
#endif
int main(){
DBPRINT();
}
Run Code Online (Sandbox Code Playgroud)
意图DBPRINT是无操作.#define DBPRINT __noop相反,警告建议使用VC的__noop扩展名.
如果查看输出的汇编列表,您将看到第二个子句被省略,即使在调试模式下也是如此.
Lor*_*ond 14
猜猜它被解释为
if((1 == 2) || NULL (-4 > 2))
printf("Hello");
Run Code Online (Sandbox Code Playgroud)
其中NULL是一个函数指针,默认情况下返回int ...运行时实际发生的是平台相关的
Visual Studio 2012为您提供以下警告:
警告C4353:使用非标准扩展:常量0作为函数表达式.请改用"__noop"函数
它是在表达式评估的那一点插入"无操作"汇编程序指令的非标准方法
实际上它是微软特有的.
出于调试目的,您可以使用__noopintrinsic,它指定不会评估函数和参数.
在您的情况下,Microsoft编译器认为您尝试使用0来执行相同操作,这就是它工作的原因,但是例如,在VS2012上它会发出警告:
warning C4353: nonstandard extension used: constant 0 as function expression. Use '__noop' function intrinsic instead.
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅此内容:http://msdn.microsoft.com/en-us/library/2a68558f(v = vs.71).aspx
| 归档时间: |
|
| 查看次数: |
2406 次 |
| 最近记录: |