VS8的CRT的调试功能太优秀了!

来看一段不小心误写的代码

#include <iostream> 
#include <fstream> 

unsigned char lenToKey(short nLen){ 
  ///取出长度的高位和低位 
  unsigned char nLenLow= nLen && 0xFF; 
  unsigned char nLenHigh= nLen >> 4; 
  return nLenLow ^ nLenHigh; 
} 

int main(int argc,char* argv[]){ 
  const char* const filename="D:\\msg\\matrixdb"; 
  std::ifstream ifs(filename); 
  char rType; 
  ifs.get(&rType,sizeof(rType)); 
  short nLen; 
  ifs.get(&rType,sizeof(nLen)); 
  unsigned char key=lenToKey(nLen); 
  return 0; 
}

变量nLen所在的内存,未经初始化便投入使用。如果是在Freebsd下,不借助于valgrind这样的错误要花很久才能调试出来。而在VS下按F5,瞬间得到这样的诊断信息:
“Run-Time Check Failure #3 - The variable 'nLen' is being used without being defined.”
试问,任何unix的libc,有哪个能做到这么智能?

此博客中的热门博文

少写代码,多读别人写的代码

在windows下使用llvm+clang

tensorflow distributed runtime初窥