Linked list confusion :(
Author |
Message |
jcollins1991
|
Posted: Wed Mar 16, 2011 1:06 pm Post subject: Linked list confusion :( |
|
|
First, when I compile and run on OSX and run the executable I get a segmentation fault and it crashes. When I run with valgrind on OSX with the same executable the code works perfectly. When I compile and run on Linux I get an infinite loop in my elements (a -> b -> c -> b -> c ...), which I don't understand since I always set the end to "NULL". Finally, when I run on Linux with Valgrind it works properly :/. It appears valgrind is suppressing something, but I can't figure out what exactly. I can guess that maybe the infinite loop is what's causing the segmentation fault on OSX, but I can't find anything in my code that'd be causing this.
Sadly this is for part of an assignment so I can't post the code, but if anyone has any ideas of what may be happening they'd be greatly appreciated. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Wed Mar 16, 2011 1:15 pm Post subject: RE:Linked list confusion :( |
|
|
Depending on a compiler, they might handle NULL pointer dereferences differently. See if Linux's execution puts anything onto STDERR.
There's obviously a bug somewhere in this code, and it would help you the most to figure out exactly where the segfault occurs. If Valgrind is taking different execution paths, perhaps you can try GDB instead. Or a bunch of print statements... don't forget to flush your buffers before the crash. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Insectoid
|
Posted: Wed Mar 16, 2011 1:29 pm Post subject: RE:Linked list confusion :( |
|
|
I have no issues with linked lists in gcc. I do set the end pointer to NULL.
Like Tony said, printf is the greatest debugger. Some students laugh at me when I suggest printfs, then wonder why my code works and theirs doesn't. |
|
|
|
|
|
jcollins1991
|
Posted: Wed Mar 16, 2011 1:34 pm Post subject: Re: Linked list confusion :( |
|
|
Ok figured it out now after going through all my pointer assignments ><... I was setting a pointer to null instead of its rest to null... + I always use cout for debugging anyways |
|
|
|
|
|
|
|