View previous topic :: View next topic |
Author |
Message |
stanhebben
Joined: 18 Jan 2007 Posts: 3
|
Posted: Thu Jan 18, 2007 2:04 am Post subject: Strange Access Violation error |
|
|
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 |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
Posted: Thu Jan 18, 2007 8:00 am Post subject: Re: Strange Access Violation error |
|
|
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 |
|
|
stanhebben
Joined: 18 Jan 2007 Posts: 3
|
Posted: Thu Jan 18, 2007 12:04 pm Post subject: |
|
|
Ah, I see. Indeed, that's what I needed. Thanks. |
|
Back to top |
|
|
|