Gdb Error Attempt To Dereference A Generic Pointer
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack
Gdb Print Void Pointer
Overflow the company Business Learn more about hiring developers or posting ads with us gdb pointer Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community
Gdb Dereference Register
of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up GDB: Attempt to dereference generic pointer up vote 9 down vote favorite 4 How can I make GDB do extra dereferences in a printing function like x/s? When I try explicit dereferences in x/ I get the error "Attempt to dereference a generic pointer". Using x/ multiple times works, since each use includes an implicit dereference, but this is annoying since I have to copy and paste each intermediate result. Example Consider the very useful C program, example.c: #include
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up how to check the value of pointer (void) not be zero (Attempt to dereference a generic pointer) up vote 1 down vote favorite Sorry http://stackoverflow.com/questions/20414699/gdb-attempt-to-dereference-generic-pointer it must be very simple question , but since I tried in diffrenet ways without any success I have to ask here to be sure. C programming : There is a struct name rtg. EDIT: type of mtch is LLIST type of initial is LL_NODE typr of obj is pointer (void) . Using gdb when I check (gdb) print *rtg->mtch->initial->obj Attempt to dereference a generic pointer. (gdb) print rtg->mtch->initial->obj $10 = (void *) 0x4cc660 (gdb) x http://stackoverflow.com/questions/15251805/how-to-check-the-value-of-pointer-void-not-be-zero-attempt-to-dereference-a-g 0x4cc660 0x4cc660: 0x00000000 This null pointer causes segfault in my program. What I am looking for is simply how to check the value of what rtg->mtch->initial->obj is pointing not be zero? (to prevent above segfault) I mean if I check with if (rtg->mtch->initial->obj) , it would just check if pointer obj , adress not be zero (this is not what I intend , I intend to check the value of that pointer not be zero (but when I use * before checking in gdb it says "Attempt to dereference a generic pointer". So what is the correct way to check that value not be zero (and prevent this segfault)? Edit : i had tried this if (*((char *) rtg->mtch->initial->obj) != NULL) but i got compile warning : warning: comparison between pointer and integer EDIT2 , here what are these defined in the source code ECM_REQUEST is struct ECM_REQUEST rtg; in this struct defind mtch as LLIST mtch; initial is LL_NODE obj is a pointer i want to check obj value not be zero so now everything are clear about my question isn't it? Thanks c pointers null segmentation-fault share|improve this question edited Mar 6 '13 at 16:28 asked Mar 6 '13 at 15:47 nima tajfar 2828 8 You must show more code, like the structure declarations. Don't talk about them, show them. &nd
Programming Boards C++ Programming dereferencing a void * Getting started with C or C++ | C Tutorial | C++ Tutorial | C and C++ FAQ | Get a compiler | Fixes for common problems Thread: dereferencing http://cboard.cprogramming.com/cplusplus-programming/30048-dereferencing-void-*.html a void * Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 12-04-2002 #1 pointing Guest dereferencing a void * i use a void pointer to point either one of two distinct class types. say: class x{...} class y{...} and void *p; x object1; y object2; p = (x *)&object1; etc.... and somehow when i need to reach to one of object1's gdb error fields: i want to use p to reach the object but i receive "attempt to dereference a generic pointer" error? is there anybody who has faced this error before? thanks in advance 12-04-2002 #2 Polymorphic OOP View Profile View Forum Posts Visit Homepage Programming Sex-God Join Date Nov 2002 Posts 1,078 You have to typecast the void pointer to a pointer to the type you want to access. so *(x*)(p) But you really should not have to gdb error attempt deal with void pointers much in C++ because of templating and inheritance. void pointers are generally more necissary in C than C++. My collection of useless files Contact Me! 12-04-2002 #3 pointing View Profile View Forum Posts Registered User Join Date Dec 2002 Posts 4 yeah that was pretty much the same solution that i have tried but it didn't work you might be right about not using void * in C++ but does anyone has an advice to use what when i need to point two distict types via only one pointer. (i'm implemeting a b+ tree and i need to point to internal nodes and leaf nodes with a unique type of pointer) 12-04-2002 #4 Polymorphic OOP View Profile View Forum Posts Visit Homepage Programming Sex-God Join Date Nov 2002 Posts 1,078 That should work. Make sure you encase that in parenthesis before you use it. You can use the arrow operator instead of dereferencing the cast pointer as well. My collection of useless files Contact Me! 12-04-2002 #5 pointing View Profile View Forum Posts Registered User Join Date Dec 2002 Posts 4 that's what i'm doing actually, it's probably a property of C++ but i couldn't fix let me be more informative: class Int_Node{ public: //internal node vector