我一直在尝试调试一些小东西,并且在尝试这样做时几乎疯了.经过几个小时的解决问题后,我终于得到了一段代码,这是我问题的根源:
#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;
}
Run Code Online (Sandbox Code Playgroud)
有了这个编译,使用:
g++ -std=c++11 -ggdb -O0 -pedantic -Wall -Wextra -Wno-nonnull -fkeep-inline-functions
Run Code Online (Sandbox Code Playgroud)
然后我尝试以下方法:
(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)
Run Code Online (Sandbox Code Playgroud)
可悲的是,4现在等于4293588256.到底是怎么回事?此外,如果我在创建堆栈之前中断程序,GDB会正确显示大小.
编辑:我在Windows 8.1,版本的东西是:G ++ 4.8.1; GDB 7.6.1
| 归档时间: |
|
| 查看次数: |
166 次 |
| 最近记录: |