c++ - How to test/verify that zero-initialization takes place -
i trying test 0 initialization on virtual machine g++ options -std=c++98, -std=c++03, -std=c++11
unfortunately there not many garbage values , see zeros in place shouldn't be.
how force random values can test this?
#include <iostream> #include <string> using namespace std; class { public: int a; }; class b { public: b(){} int x; }; int main() { { int tab[50000] = {0}; } a; a* aa = new a; b b; b* bb = new b; cout << a.a << endl; cout << aa->a << endl; cout << b.x << endl; cout << bb->x << endl; return 0; }
you not guaranteed see random numbers. c/c++ standard says uninitialized values undefined, cannot values have. 0 ok (maybe virual machine zeros memory before allocating).
if need random numbers, generate them using <random>
Comments
Post a Comment