944,163 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3298
  • C++ RSS
May 29th, 2005
0

Bug when creating linked lists in Dev C++

Expand Post »
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:
C++ Syntax (Toggle Plain Text)
  1. struct llnode{
  2. ....
  3. llnode *next;
  4. };
  5.  
  6. llnode *llstart = NULL;
  7. llnode *lltemp;
  8. llnode *lltemp2;
  9.  
  10. void main(void)
  11. {
  12. ...
  13. if(llstart == NULL)
  14. {
  15. lltemp = new(llnode);
  16. .... //fill it with my information
  17. lltemp->next = NULL;
  18. llstart = lltemp;
  19. }
  20. }
  21.  
  22. //when I need to add other nodes
  23. void AddNode()
  24. {
  25. lltemp = new(llnode);
  26. ....//add information
  27. lltemp->next = NULL;
  28.  
  29. llnode2 = llstart;
  30.  
  31. while(lltemp2 ->next != NULL)
  32. {lltemp2 = lltemp2->next;}
  33.  
  34. lltemp2->next = lltemp;
  35. }

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.
Similar Threads
Reputation Points: 11
Solved Threads: 0
Newbie Poster
amura97 is offline Offline
5 posts
since May 2005
May 29th, 2005
0

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

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.
Reputation Points: 35
Solved Threads: 3
Posting Whiz in Training
Dogtree is offline Offline
232 posts
since May 2005
Jun 4th, 2005
0

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

i can see only one error in main function. in dev-cpp it shouldn't be void but int
Reputation Points: 10
Solved Threads: 0
Newbie Poster
typek is offline Offline
7 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: openGL problem
Next Thread in C++ Forum Timeline: Draw a house into a window in C++ (?!)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC