簡體   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