Hello everyone,
I recently wrote a very large program in Borland C++ (version 4) that implements a lot of linked lists. For many reasons I am now obliged to migrate to Dev C++, but when I run my software I get a "Access violation (segmentation fault)" error. This happens whenever the program steps into a code portion that creates a linked list (it usually (but not always) happens when the first linked list is being created). The program worked perfectly under Borland Builder 4. So I am wondering if there is an inherent problem with linked list in Dev C++ that I am unaware of (a check on Google reveals no bug concern on this matter). Could the error lie in the way I create linked lists:
struct llnode{
....
llnode *next;
};
llnode *llstart = NULL;
llnode *lltemp;
llnode *lltemp2;
void main(void)
{
...
if(llstart == NULL)
{
lltemp = new(llnode);
.... //fill it with my information
lltemp->next = NULL;
llstart = lltemp;
}
}
//when I need to add other nodes
void AddNode()
{
lltemp = new(llnode);
....//add information
lltemp->next = NULL;
llnode2 = llstart;
while(lltemp2 ->next != NULL)
{lltemp2 = lltemp2->next;}
lltemp2->next = lltemp;
}
I know the above works in Borland C++ version 4, but is it an obsolete way which makes more recent compiler go crazy?
Any suggestions would be greatly appreciated.