User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,022 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,653 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1805 | Replies: 2
Reply
Join Date: May 2005
Posts: 5
Reputation: amura97 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
amura97 amura97 is offline Offline
Newbie Poster

Bug when creating linked lists in Dev C++

  #1  
May 29th, 2005
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: Bug when creating linked lists in Dev C++

  #2  
May 29th, 2005
Post some complete code that breaks under Dev-C++. It looks like you wrote what you think is the same thing as the relevant parts of the program, but since the code you posted won't compile even after removing the .... parts and adding necessary headers.

And rule #1 when your code works on one compiler but not another: It's almost always your fault. You would do better to assume that your code is wrong rather than an inherent problem with the compiler.
Reply With Quote  
Join Date: May 2005
Posts: 7
Reputation: typek is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
typek typek is offline Offline
Newbie Poster

Re: Bug when creating linked lists in Dev C++

  #3  
Jun 4th, 2005
i can see only one error in main function. in dev-cpp it shouldn't be void but int
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 1:39 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC