繁体   English   中英

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

[英]In gdb sizeof(Apple::record_) is zero. But It runs well

我遇到了一个非常奇怪的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;
    }

听起来像是GDB或编译器中的错误。

您的编译器较旧(当前为4.6.1)。 您没有说要使用哪个版本的GDB,但它可能也不是最新版本(7.3.1)。

如果您可以重现当前版本的GCC和GDB的问题,则应提交错误报告。

在以下版本的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.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM