Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

what the flying fuck

Name: Anonymous 2008-12-02 20:12

This C++ code is causing a segfault, and I can't understand why. Yes, it's homework, but I don't want my homework done. I just want the one bug that's pissing me off and that I can't fix fixed. You'd think it's the pointer fucking up, but apparently not. Here's the code causing the issue, with printf's to figure out where the hell it's fucking up:

printf("attempting get next\n");
list = list->getNext();
list->print();
printf("attempting remove previous\n");
list->removePrevious();
printf("success!\n");

The list->print(); is to ensure that the pointer's pointing at something of value. This is never what actually fucks it up, so apparently the pointer's not pointing off into nowhere.

Here's the code for removePrevious(), again with debugging printf's:

printf("deleting previous");
previous->setPrevious(NULL);
previous->setNext(NULL);
delete previous;
printf("...done\n");
previous == NULL;

It never actually prints out "deleting previous". It evidently segfaults right when it tries to call removePrevious().

Name: Anonymous 2008-12-02 20:22

I can't believe you don't see it XD

Name: Anonymous 2008-12-02 20:34

I know how to fix the segfault.  And I can tell you how.

(661) 333-0012
EXPERT PROGRAMMER'S OFFICE of California, apply now!

Name: Anonymous 2008-12-02 20:38

Probably not related, but when you remove "previous", you don't connect the element before previous to the element after previous, and vice versa.

Name: Anonymous 2008-12-02 20:54

>>4
Okay, I fixed that. Here's the new removePrevious():

void LinkedList::removePrevious()
{
    printf("starting removePrevious()");
    if(next != NULL)
    {
        LinkedList *tempNode = previous->getPrevious();
        next->setPrevious(NULL);
        next->setNext(NULL);
        delete next;
        next = tempNode;
        previous->setNext(this);
    }
    printf("...done\n");
}
Here's the output:

Please input a choice: d 1
attempting get next
Value: 62
attempting remove previous
Segmentation fault

"d 1" is my input, telling it to delete the first node.
"attempting get next" is right before it tries to use getNext().
"Value: 62" is from print().
"attempting remove previous" is from the step immediately before calling removePrevious().
...and then segfault.

Somehow, it never gets to printing "starting removePrevious()". It's the call to removePrevious() itself that seems to be causing the segfault somehow.

Name: Anonymous 2008-12-02 21:08

void LinkedList::removePrevious()
        delete next;
wat

Name: Anonymous 2008-12-02 21:11

>>5
I recommend starting over from the beginning, writing your linked list properly this time. Your mickey mouse code is both confusing and wrong.

Protip: Have separate "Node" and "LinkedList" classes to begin with.

Name: Anonymous 2008-12-02 23:12

typedef LinkedList Node
typedef Node LinkedList

Name: Anonymous 2008-12-02 23:13

typedef LinkedList Node
typedef Node LinkedList

Name: Anonymous 2008-12-03 5:41

How about some Java code?

Name: Anonymous 2008-12-03 8:16

rm *.java && rm *.class

Name: Anonymous 2008-12-03 9:36

Learn2gdb

Name: Anonymous 2008-12-03 13:06

>>11
rm *.java *.class

Name: Anonymous 2008-12-03 13:30

>>13
OPTIMIZED

Name: Anonymous 2008-12-03 15:13

>>13
rm *.{java,class}

Name: Anonymous 2008-12-03 17:28

find . -iname '*.java' -or -iname '*.class' -print0|xargs -0 rm

Name: Anonymous 2008-12-03 17:33

>>16
-exec rm {} \;

Name: Anonymous 2008-12-03 17:36

find -E / -regex '.*\.(java|class)' -delete

Name: Anonymous 2008-12-03 19:34

You... named your nodes "next" and "previous"? What the fuck is wrong with your linked list?

Name: Anonymous 2008-12-04 3:41

sudo rm -rf /

DO IT FAGGOT!

Name: Anonymous 2008-12-04 8:30

>>20
> rm -rf /
rm: "/" may not be removed

Name: Anonymous 2008-12-04 9:05

>>21
rm `which rm`

Name: Anonymous 2011-02-02 23:10

Name: Anonymous 2013-01-19 21:00

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Don't change these.
Name: Email:
Entire Thread Thread List