Re: [ooc-compiler] Compiler error
Brought to you by:
mva
|
From: Stewart G. <sgr...@ii...> - 2010-07-29 02:51:49
|
Hi Frank,
Sorry for the delay. I just tested this code and it works fine for me.
Which version of oo2c and gcc are you running?
Can you post the output files obj/Test.c and obj/L.c? Do a clean build
after first removing all of the files under the sym and obj directories.
One slight inefficiency is that L.IsEmpty should be:
PROCEDURE IsEmpty* (VAR list:Header): BOOLEAN;
Otherwise it makes a copy of the record before testing the pointer.
Cheers,
Stewart
Frank Hrebabetzky wrote:
> Hi there,
>
> I guess I found a compiler error. I have a module L which implements a
> rudimentary list and a module Test which imports L:
>
>
> MODULE L;
> IMPORT Out;
>
> TYPE
> Item* = POINTER TO ItemD;
> ItemD* = RECORD
> next-: Item;
> END;
>
> Header* = RECORD
> first-, last-: Item;
> END;
>
> PROCEDURE IsEmpty* (list:Header): BOOLEAN;
> BEGIN RETURN list.first=NIL
> END IsEmpty;
>
> PROCEDURE Init* (VAR list:Header);
> BEGIN
> list.first:= NIL; list.last:= NIL;
> Out.String("List initialized"); Out.Ln;
> END Init;
>
> END L.
>
>
> MODULE Test;
> IMPORT L, Out;
>
> TYPE
> Node = POINTER TO NodeD;
> NodeD = RECORD (L.ItemD)
> sons-: L.Header;
> END;
> VAR n1: Node;
>
> PROCEDURE (node:Node) Init;
> BEGIN
> L.Init (node.sons);
> IF ~L.IsEmpty(node.sons) THEN
> Out.String("n1.sons not empty!"); Out.Ln;
> END
> END Init;
>
> BEGIN
> NEW (n1);
> n1.Init;
> END Test.
>
>
> Executing Test prints the following:
>
> List initialized
> n1.sons not empty!
>
> which means that n1.Init didn't change n1. This is an error, isn't it?
> If details matter I can tell them (platform, versions etc.).
>
|