连等的if语句_小心编译器

来源:互联网 发布:佣金搜索采集软件 编辑:程序博客网 时间:2024/05/16 18:59

 UINT nR = GetRValue (clrDest);
UINT nG = GetGValue (clrDest);
UINT nB =GetBValue (clrDest);
// if(nR == nG == nB == 0)
if((nR == 0)&&(nG==0)&&(nB == 0)) 这两条if语句竟然不是等价的。。

这是在vs2005编译器下测试得到的情况,不知道其他的编译器是不是这样工作的。以后写代码一定要小心啊!

 

vs2005 测试代码:

// testIf.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
 UINT nR = 25;
 UINT nG = 25;
 UINT nB = 23;
 // if(nR == nG == nB == 0)
 if((nR == 0)&&(nG==0)&&(nB == 0))
 {
  printf("dddd");
 }
 else
 {
  printf("why_why");
 }
 return 0;
}

 

 

原创粉丝点击