Michael Daniluk
2009-05-07 19:09:32 UTC
Hello All,
I am waiting for the Wirth book to come in the mail but in the meantime
I encountered a bug for which I can find no references. Here are some
type declarations that I made all in the same file:
TYPE LexAnalyzer = POINTER TO TokenList;
TYPE TokenNodePointer = POINTER TO TokenNode;
TYPE TokenNode = RECORD
type : TypeOfTerminal;
value : String;
next : TokenNodePointer;
END;
TYPE TokenList = RECORD
headToken : TokenNodePointer;
tailToken : TokenNodePointer;
currentToken : TokenNodePointer;
END;
The key here is the TokenList record. I want to initialize it so
the three pointers it contains are all initialzed to the value NIL. Here
is the code I am using to do this.
PROCEDURE InitializeTokenList(VAR la : LexAnalyzer);
VAR tl : TokenList;
BEGIN
ALLOCATE(la, SIZE(TokenList));
tl := la^;
tl.headToken := NIL;
tl.tailToken := NIL;
tl.currentToken := NIL;
END InitializeTokenList;
My program compiles but I ran into some erroneous behaviour at runtime.
I tracked down the bug to the function above. It turns out that though
tl.headToken and tl.tailToken are both successfully initialized,
tl.currentToken is not successfully initialized to NIL. I confirmed this
with several runs and Print statements. I have not encountered behaviour
like this in any other programming language and I am very troubled by
it. The only compiler warning (I am using StonyBrook and building for
Windows) I get is about the TokenNode record:
"Record field not naturally aligned"
Does anyone have any ideas about this?
truly,
Michael
I am waiting for the Wirth book to come in the mail but in the meantime
I encountered a bug for which I can find no references. Here are some
type declarations that I made all in the same file:
TYPE LexAnalyzer = POINTER TO TokenList;
TYPE TokenNodePointer = POINTER TO TokenNode;
TYPE TokenNode = RECORD
type : TypeOfTerminal;
value : String;
next : TokenNodePointer;
END;
TYPE TokenList = RECORD
headToken : TokenNodePointer;
tailToken : TokenNodePointer;
currentToken : TokenNodePointer;
END;
The key here is the TokenList record. I want to initialize it so
the three pointers it contains are all initialzed to the value NIL. Here
is the code I am using to do this.
PROCEDURE InitializeTokenList(VAR la : LexAnalyzer);
VAR tl : TokenList;
BEGIN
ALLOCATE(la, SIZE(TokenList));
tl := la^;
tl.headToken := NIL;
tl.tailToken := NIL;
tl.currentToken := NIL;
END InitializeTokenList;
My program compiles but I ran into some erroneous behaviour at runtime.
I tracked down the bug to the function above. It turns out that though
tl.headToken and tl.tailToken are both successfully initialized,
tl.currentToken is not successfully initialized to NIL. I confirmed this
with several runs and Print statements. I have not encountered behaviour
like this in any other programming language and I am very troubled by
it. The only compiler warning (I am using StonyBrook and building for
Windows) I get is about the TokenNode record:
"Record field not naturally aligned"
Does anyone have any ideas about this?
truly,
Michael