2010-05-07 54 views
5
struct ptr{ 
    int node; 
    ptr *next; 
    ptr(){} 
    ptr(int _node, ptr *_next){ node=_node; next=_next; } 
}; 
struct list_t{ 
    ptr *sht; 
    int size; 
    void push(int node){ 
     size++; 
     sht=new ptr(node,sht); 
    } 
}shthead[100001], comp[200001], tree[200001]; 

的结构PTR被用作一个链表。但是当我在gdb中调试代码时,我发现ptr *全部转换为void *。
GDB输出:C++:为什么一个结构的自指针自动改变到void *

(gdb) pt ptr 
type = struct ptr { 
    int node; 
    void *next; 
    public: 
    ptr(void); 
    ptr(int, void *); 
}

不过,我仍然可以看到该结构的数据,如果我隐蔽他们回到PTR *在gdb。
请问这是什么原因?

我使用的是Arch Linux,GNOME,g ++ 4.5.0,gdb 7.1。没有任何编译标志,但是-g。
This GDB was configured as "i686-pc-linux-gnu"

+0

它在我的系统上显示'ptr *'。您使用了哪些汇编标志?什么版本的g ++和gdb? – Thomas 2010-05-07 07:29:37

+0

奇怪,我也使用gdb 7.1,但是g ++ 4.4.3。 4.5发布说明并不暗示在这个方向上有任何改变。 http://gcc.gnu.org/gcc-4.5/changes.html – Thomas 2010-05-07 07:59:44

+0

只是为了填补更多的数据点,使用gdb 7.0.1我得到了正确的答案g ++ 4.2.4和4.3.3,但4.5。 0 gdb将指针显示为“void *”。看起来像gcc(或gdb?)中的错误 – 2010-05-07 08:57:05

回答

1

在OS X上为我的作品精细

(gdb) pt ptr 
type = class ptr { 
    public: 
    int node; 
    ptr *next; 

    ptr(void); 
    ptr(int, ptr *); 
} 

gdb的版本:

Shadow:code dkrauss$ gdb -v 
GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009) 
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". 
0

应该指出,“ptr”是/不是一个智能指针,它只是一个结构,甚至没有析构函数。

(智能指针在C++ land中有非常精确的含义)

+0

嗯,我很抱歉。我不应该在这里说出一个“聪明的指针”,并对它们有一个模糊的理解。该文本现在已被更正。 – Stone 2010-12-12 04:21:12

+0

没有伤害。 :) – Arafangion 2010-12-13 01:26:15