I tried to debug a little thing and almost went crazy trying to do it. After hours of finding out the problem, I finally have a piece of code that is the root of my problem:
#include <iostream> #include <vector> #include <stack> using namespace std; int main() { std::vector<int> foo = std::vector<int>(); foo.push_back(0); foo.push_back(11); foo.push_back(222); foo.push_back(3333); std::stack<int> bar = std::stack<int>(); cout << endl << foo.size() << endl << endl; return 0; }
Compiled using:
g++ -std=c++11 -ggdb -O0 -pedantic -Wall -Wextra -Wno-nonnull -fkeep-inline-functions
Then I will try the following:
(gdb) br 18 Breakpoint 1 at 0x40170c: file ./....cpp, line 18. (gdb) r Starting program: ... [New Thread 15620.0x3c3c] Breakpoint 1, main () at ./....cpp:18 18 cout << endl << foo.size() << endl << endl; (gdb) p foo.size() $1 = 4293588256 (gdb) c Continuing. 4 [Inferior 1 (process 15620) exited normally] (gdb)
Obviously, now 4 is now 4293588256. What the hell? Also, if I crash the program before creating the stack, GDB displays the size correctly.
EDIT: I'm on windows 8.1, material version: g ++ 4.8.1; GDB 7.6.1
source share