2011-09-28 37 views
0

我遇到了一個非常奇怪的g ++問題。在gdb中sizeof(Apple :: record_)爲零。但它運行良好

流動程序的輸出是「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; 
    } 
+0

對不起,我誤解了你的問題。所以我刪除了我的答案。 – Mysticial

回答

0

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

聽起來像GDB或編譯器中的錯誤。

你的編譯器是舊的(當前是4.6.1)。你沒有說你使用的是哪個版本的GDB,但它可能不是最新的(7.3.1)。

如果您可以用當前版本的GCC和GDB重現問題,則應提交錯誤報告。

相關問題