Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: why a self pointer of a struct automatically changes to void*

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];

The struct ptr is used as a linked list. But when I debug the code in gdb, I found that the ptr*'s were all converted to void*.
GDB output:

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

However, I can still see the data of the struct if I covert them back to ptr* in gdb.
What's the reason for this please?

I'm using Arch Linux, GNOME, g++ 4.5.0, gdb 7.1. Without any compilation flags but a -g.
This GDB was configured as "i686-pc-linux-gnu"

like image 906
Stone Avatar asked Nov 06 '22 13:11

Stone


1 Answers

Works fine for me on OS X.

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

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

gdb version:

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".
like image 180
Potatoswatter Avatar answered Nov 12 '22 09:11

Potatoswatter