I learned something interesting today: if I have a standard vector v and I run code like:
std::vector<float> v;
for (int i = 0; i < 2; i++) v.push_back(2.);
if I call v[2]
I will not get a segmentation fault, because the operator[]
does not do bounds checking. I was getting some absurdly small number, but I was curious what the default behavior of push_back is and what I should expect from overflowing a vector bounds. I would assume it would have to allocate more space than just the next float. How much? Is this in the standard, or is it compiler-specific?