2011-09-28 2 views
0

매우 이상한 g ++ 문제가 발생했습니다.gdb에서 sizeof (Apple :: record_)가 0입니다. 하지만 잘 돌아갑니다.

흐르는 프로그램의 출력은 "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을 반환합니다 (시스템의 int와 포인터가 각각 8 바이트이기 때문에 24가 아닙니다).

아마도 당신이 사용하고있는 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에서 문제를 재현 할 수 있으면 버그 보고서를 제출해야합니다.