FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Strange Access Violation error

 
Post new topic   Reply to topic     Forum Index -> General
View previous topic :: View next topic  
Author Message
stanhebben



Joined: 18 Jan 2007
Posts: 3

PostPosted: Thu Jan 18, 2007 2:04 am    Post subject: Strange Access Violation error Reply with quote

I'm currently experimenting with D, and now I have a strange Acces Violation Error.

I stripped down the code to a minimum, to find the reason of this error. It compiles fine, and I don't find any bug in my code.

The code creates a linked list then takes the first element and checks if it is null. (which is always the case, because I don't add anything).

The line that checks if the first element is null seems to cause the access violation error. (if I comment it out, I have no problems) However, I don't see how it can cause such error.

Does anyone have a clue what I did wrong?

test.d:
Code:

/* main program */
int main(char[][] args) {
  LinkedList errors = new LinkedList();
 
  LinkedListNode error = errors.getFirstNode();
  if (error != null) return 1;  /* this line causes an access violation */
 
  return 0;
}

/* linked list of strings */
class LinkedList {
protected: LinkedListNode first;
public:
  this() { first = null; }
 
  LinkedListNode getFirstNode() { return first; }
}

/* element of a linked list */
class LinkedListNode {
public:
  LinkedListNode next;
  char[] value;
 
  this(char[] value) { this.value = value; next = null; }
}


I compiled the code on windows using \dmd\bin\dmd test.d .
Back to top
View user's profile Send private message
jcc7



Joined: 22 Feb 2004
Posts: 657
Location: Muskogee, OK, USA

PostPosted: Thu Jan 18, 2007 8:00 am    Post subject: Re: Strange Access Violation error Reply with quote

stanhebben wrote:
Code:
if (error != null) return 1;  /* this line causes an access violation */
Try changing the "!=" to "!is" since you're comparing to null. I'm not sure if this is the right solution, but it made the "Access Violation" go away in my test.
Back to top
View user's profile Send private message AIM Address
stanhebben



Joined: 18 Jan 2007
Posts: 3

PostPosted: Thu Jan 18, 2007 12:04 pm    Post subject: Reply with quote

Ah, I see. Indeed, that's what I needed. Thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> General All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group