在VS调试器中注意到内存地址通常是偶数后我尝试了以下程序(MS Visual Studio 2012)
struct noise { int data[3]; }; int _tmain(int argc,_TCHAR* argv[]) { std::vector<noise*> vn; std::vector<std::complex<double>*> vv; for (int i(0); i < 90000; ++i) { std::complex<double> *cur = new std::complex<double>(1,1); assert( ! ((int)cur&1) ); // assert if adress is not even vv.push_back(cur); if ( ! (i% (rand()%5 + 1)) ) vn.push_back(new noise); } for (std::size_t i(0),ie(vv.size()); i < ie; ++i) { delete vv[i]; } for (std::size_t i(0),ie(vn.size()); i < ie; ++i) { delete vn[i]; } system("PAUSE"); return 0; }
它绝不断言!怎么会这样?有没有办法让它断言?作为副作用,这有什么用途吗?