I stumbled upon a curious behaviour of std::array
. Some containers such as std::vector
initialise all cells, such that a vector of int
will be a vector full of zeros by default. I tested whether this was also true for std::array
. I discovered two things:
1) it looks like most cells are being initialised (but probably this has other reasons) and some are not.
2) the cells that are not being initialised are always the same. This holds true between separate executions of the program as well as between separate compilations. Consider the output below. for this code:
std::array<int, 100> a;
for (auto x : a) std::cout << x << " ";
I wonder now why these two things are this way. What causes this apparent initialisation (which probably is something else) and why are the non-initialised cells always the same ones (and sometimes eben have the same value as in the execution before)?
$ cocompile test.cpp
$ ./a.out
1583671832 1235456 1235456 1235456 1235456 1235456 0 0 0 0
$ ./a.out
1539111448 1235456 1235456 1235456 1235456 1235456 0 0 0 0
$ ./a.out
1509472792 1235456 1235456 1235456 1235456 1235456 0 0 0 0
$ cocompile test.cpp
$ ./a.out
1551280664 32767 1551280664 32767 55136256 1 0 1 71644448 1 71644352 1 0 0 0 0 0 0 0 0
$ ./a.out
1413601816 32767 1413601816 32767 192815104 1 0 1 407872800 1 407872704 1 0 0 0 0 0 0 0 0
$ ./a.out
1542519320 32767 1542519320 32767 63897600 1 0 1 129918240 1 129918144 1 0 0 0 0 0 0 0 0
$ cocompile test.cpp
$ ./a.out
1510054424 32767 1 0 1510054368 32767 145269321 1 1510054400 32767 1510054400 32767 1510054424 32767 96362496 1 0 1 145265952 1 145265856 1 0 0 0 0 0 0 0 0
$ ./a.out
1394678296 32767 1 0 1394678240 32767 378704457 1 1394678272 32767 1394678272 32767 1394678296 32767 211738624 1 0 1 378701088 1 378700992 1 0 0 0 0 0 0 0 0
$ ./a.out
1436727832 32767 1 0 1436727776 32767 353342025 1 1436727808 32767 1436727808 32767 1436727832 32767 169689088 1 0 1 353338656 1 353338560 1 0 0 0 0 0 0 0 0