You are not logged in.

#1 2008-09-25 07:27:23

Stythys
Member
From: SF Bay Area
Registered: 2008-05-18
Posts: 878
Website

Segfault

I'm kinda new to C++ so not sure what to do here....

I just started trying to run this: http://paste.pocoo.org/show/86157/

It compiles fine but I get this really weird segfault error that makes no sense when trying to run it, looks like when I access a function inside my linklist class. Anyone else get a similar error? what's it mean? =/


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol

Offline

#2 2008-09-25 07:59:45

WhiteMagic
Member
Registered: 2007-03-01
Posts: 85

Re: Segfault

I only had a quick look at it and it seems that at least the linklist::add method doesn't behave the way you want it to.

I tried adding an item to a newly created list.

linklist list;
list.add("t1", 50, 1, 1);

This results in a segfaul in the

while(q->link!=NULL)

part of the add method. I didn't look further but what I would do is to build small examples where you can test your list implementation first. As for debugging these segfaults you'll most likely have to use a debugger. Segfaults often have to do with access to memory in areas where you have no permission or nothing was initialized.

I suppose the whole purpose of the program is to write your own list implementation, because if not you might want to use the STL list implementation.

Last edited by WhiteMagic (2008-09-25 08:01:20)

Offline

#3 2008-09-25 08:01:24

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,396
Website

Re: Segfault

I haven't tried it but it means you are probably doing something wrong with pointers (writing to uninitialized memory, deleting an uninitialized pointer).

I'd use an "put print statements in the code" strategy for finding the offending line.

Offline

#4 2008-09-25 08:50:04

Stythys
Member
From: SF Bay Area
Registered: 2008-05-18
Posts: 878
Website

Re: Segfault

ah yeah it was an uninitialized pointer.

thanks guys big_smile


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol

Offline

Board footer

Powered by FluxBB