2011-09-28 92 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重现问题,则应提交错误报告。

相关问题