Click to See Complete Forum and Search --> : segmentation fault (core dump) w/ c++ function call


wsimmons
09-27-2001, 12:33 AM
I am getting a segmentation fault (core dumped) when a program that I am writing calls the following function:

void test_fx()
{
MainDataSetPtr here_ptr;//local scope
here_ptr = head;
do
{
cout<<head->d_structCloneID<<"\n";
cout<<head->d_structSubclone<<"\n";
//a few more struct variables that I don't want to
//take the time to write at the moment
here_ptr = here_ptr-> link_down;
}while (here_ptr-> link_down != NULL);
return;
}

The struct worked fine in other functions (I can load it with data)that I have used in the porgram. but now that I am trying to extact the data from it for processing (including file output streams) there seems to be difficulty in the programming. Any help with this? Thank you.

:confused:

The Kooman
09-27-2001, 04:41 AM
void test_fx()
{
MainDataSetPtr here_ptr;//local scope
here_ptr = head;
do
{
cout<<head->d_structCloneID<<"\n";
cout<<head->d_structSubclone<<"\n";
//a few more struct variables that I don't want to
//take the time to write at the moment
here_ptr = here_ptr-> link_down;
}while (here_ptr-> link_down != NULL);
return;
}

The struct worked fine in other functions (I can load it with data)that I have used in the porgram. but now that I am trying to extact the data from it for processing (including file output streams) there seems to be difficulty in the programming. Any help with this? Thank you.

:confused:[/QB]

Whoa, I find a whole load of non-local variables out there - what are they (in terms of data types)? Where are they initialized?
MainDataSetPtr - what struct is this?
head - whats this? More importantly, where is it initialized?
d_structCloneID ?
d_structSubclone ?


I'm pretty sure its because you're accessing a variable (pointer) thats not initialized. But anyhow, do give in those inputs before we can tackle it ... the rest of the code would be helpful ;)!

Stuka
09-27-2001, 12:55 PM
Actually, Kooman, I think you found the error. Unless head is a global variable (which, for the sake of good code, I hope it isn't!), then that's the problem. In fact, I'd almost bet that's the issue. Of course, I won't mention the fact that this code won't work as expected, because each iteration is outputting the data from head, but I'm sure that was just a typo, right? :D

pinoy
09-27-2001, 05:53 PM
here_ptr = here_ptr-> link_down;
}while (here_ptr-> link_down != NULL);


This is very suspicious. I'm sure you can find out why.