在 gdb 中,sizeof(Apple::record_) 为零。但运行良好

发布于 2024-12-07 01:42:05 字数 767 浏览 0 评论 0原文

我遇到了一个非常奇怪的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

別甾虛僞 2024-12-14 01:42:05

在以下版本的 GDB 中,p sizeof(Apple::record_) 返回 48。(这不是 24,因为我系统上的 int 和指针各为 8 个字节)。

也许您使用的 GDB 版本在这方面有问题?

GNU gdb 6.3.50-20050815 (Apple version gdb-1705) (Fri Jul  1 10:50:06 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".

为了进行比较,这也是我的 gcc 版本。

i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

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?

GNU gdb 6.3.50-20050815 (Apple version gdb-1705) (Fri Jul  1 10:50:06 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".

Just for comparison's sake, here's my gcc version as well.

i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
千笙结 2024-12-14 01:42:05

听起来像是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文