www.digitalmars.com         C & C++   DMDScript  

D - Runtime Access Violation

reply Benji Smith <Benji_member pathlink.com> writes:
First of all, Walter, it would be nice if there was a separate newsgroup for
implementation issues encountered when writing code in D. I hate to post this
message--with its admittedly limited general interest--in a newgroup primarily
devoted to language design issues, but there doesn't currently seem to be any
choice.

Having said that, I'm having some with getting runtime Access Violation errors
whenever I try to access an object whose definition appears inside a template.
The error appears whenever I try to access the object's member data or
functions. It looks like the object reference is dereferencing as a null
pointer, which explains the Access Violation exception from windows. But I can't
see what's wrong with the code.

The simplified example below shows the way I'm setting up my code. I've left out
the actual implementations of my methods, since it doesn't seem to matter how I
implement them. I don't get any compile-time errors, so the syntax appears to be
ok.

I've stepped through the machine code in a debugger and, though I'm not an
expert in assembly language, I'm pretty sure that the exception is thrown when
the object is dereferenced to either call a function or access a data member.

Is this a bug or am I missing something fundamental in my template
definition/instantiation syntax?

Thanks,
--Benji Smith

******************************
CODE FOLLOWS:
******************************

template TStack(T) {
class Stack: Object {

private T[] stackArray;
private int stackArrayPointer = 0;
public int depth;

public void setLength(int stackArraySize) {
..
}

public void push(T data) {
..
}

public T pop() {
..
}

}
}

class DocBuilder {
private instance TStack(char[]).Stack tagStack;
build() {
tagStack.setLength(50);
tagStack.push("EXAMPLE");
stackDepth = tagStack.depth;
char[] x = tagStack.pop();
}
}
Mar 05 2003
next sibling parent reply Patrick Down <Patrick_member pathlink.com> writes:
In article <b45j8b$251n$1 digitaldaemon.com>, Benji Smith says...

class DocBuilder {
private instance TStack(char[]).Stack tagStack;
tagStack = new instance TStack(char[]).Stack();
Mar 05 2003
parent reply Benji Smith <Benji_member pathlink.com> writes:
Sheesh. Don't I feel like an idiot.

Thanks for your help.
Mar 05 2003
parent Patrick Down <Patrick_member pathlink.com> writes:
In article <b45leo$26es$1 digitaldaemon.com>, Benji Smith says...
Sheesh. Don't I feel like an idiot.

Thanks for your help.
Don't feel to bad. I've posted the exact same problem before. :)
Mar 05 2003
prev sibling parent Burton Radons <loth users.sourceforge.net> writes:
Benji Smith wrote:
 First of all, Walter, it would be nice if there was a separate newsgroup for
 implementation issues encountered when writing code in D. I hate to post this
 message--with its admittedly limited general interest--in a newgroup primarily
 devoted to language design issues, but there doesn't currently seem to be any
 choice.
Oh, we all do it, don't worry about it. Your code is wrong. This line: instance TStack(char[]).Stack tagStack; This doesn't create a TStack.Stack object, it only creates the space for it. You have to allocate such an object, such as with: tagStack = new TStack(char[]).Stack; In either a constructor or the "build" method.
Mar 05 2003