在 gdb 中,sizeof(Apple::record_) 为零。但运行良好
我遇到了一个非常奇怪的g++问题。
流动程序的输出是“24 8 3”,一切看起来都很好。但是当我使用gdb打印sizeof(Apple::record_)时,结果是0。我的gcc版本是4.5.2 (GCC)(MinGw),gdb版本是GNU gdb (GDB) 7.3 有人可以帮助我吗?
#include <iostream>
using namespace std;
struct Record {
int age;
const char* name;
};
struct Apple {
static Record record_[];
};
Record Apple::record_[] = {
{ 18, "liming i love apple" },
{ 19, "liming" },
{ 20, "liming a y z o pq x y z o o o " } };
int main() {
cout << sizeof(Apple::record_) << " " << sizeof(Apple::record_[0]) << " "
<< sizeof(Apple::record_) / sizeof(Apple::record_[0]) << endl;
return 0;
}
I encounterd a very strange g++ problem.
The output of the flowing program is "24 8 3", All things seems ok. But when I use gdb, to print sizeof(Apple::record_), it turns out to be 0. My gcc version is 4.5.2 (GCC)(MinGw), gdb version is GNU gdb (GDB) 7.3
Can anybody help me ??
#include <iostream>
using namespace std;
struct Record {
int age;
const char* name;
};
struct Apple {
static Record record_[];
};
Record Apple::record_[] = {
{ 18, "liming i love apple" },
{ 19, "liming" },
{ 20, "liming a y z o pq x y z o o o " } };
int main() {
cout << sizeof(Apple::record_) << " " << sizeof(Apple::record_[0]) << " "
<< sizeof(Apple::record_) / sizeof(Apple::record_[0]) << endl;
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在以下版本的 GDB 中,
p sizeof(Apple::record_)
返回 48。(这不是 24,因为我系统上的 int 和指针各为 8 个字节)。也许您使用的 GDB 版本在这方面有问题?
为了进行比较,这也是我的 gcc 版本。
In the following version of GDB,
p sizeof(Apple::record_)
returns 48. (This is not 24 because the int and pointer on my system are 8 bytes each).Perhaps the version of GDB you are using is buggy in this regard?
Just for comparison's sake, here's my gcc version as well.
听起来像是 GDB 或编译器中的错误。
您的编译器很旧(当前是 4.6.1)。您没有说明您正在使用哪个版本的 GDB,但它可能也不是最新的(7.3.1)。
如果您可以使用当前版本的 GCC 和 GDB 重现该问题,则应该提交错误报告。
Sounds like a bug in GDB, or in the compiler.
Your compiler is old (current is 4.6.1). You didn't say what version of GDB you are using, but it likely is not current (7.3.1) either.
If you can reproduce the problem with current version of GCC and GDB, you should file a bug report.