Reputation: 73
I'm using stl containers in my project and I discovered a weird error that I can't explain. Let's consider the following code:
#include <iostream>
#include <vector>
int main(int argc, char** argv)
{
std::vector<bool> vec;
vec.resize(5, false);
std::cout << vec.at(0);
}
This outputs 0 as expected, but if I run a memory check with drmemory it discovers an uninitialized read. Can anybody help in understanding this behaviour?
Platform: win32 ; Compiler: mingw32 - gcc 4.7.2 ; Drmemory 1.6.0 - build 2
Upvotes: 6
Views: 513
Reputation: 385174
std::vector<bool>
is a bizarre little thing, using bit twiddling to achieve its goals. I'd be content in this instance to suggest that what you're seeing is just a red herring.
That being said, you might be better off with some other container, because this template specialisation is universally despised.
Upvotes: 8