[Oberon] ARRAY OF CHAR mystery
spir
denis.spir at gmail.com
Tue Jun 22 16:05:19 MEST 2010
Hello,
In an attempt to build a string abstraction as evoked in the previous theread, I'm blocked with the following issue:
I find myself unable to assign an ARRAY OF CHAR value to an ARRAY OF CHAR variable. Below pchars is of type POINTER TO ARRAY OF CHAR. The statement
pchars^ := chars;
is refused. Below results of compilation with oo2c and obc:
oo2c --make "trial.Mod" (in directory: /home/spir/prog/oberon)
Compilation failed.
/home/spir/prog/oberon/trial.Mod:16:15: Expression not compatible with variable type `ARRAY'
obc "trial.m" (in directory: /home/spir/prog/oberon)
Compilation failed.
"trial.m", line 16: type ARRAY OF CHAR is needed on the RHS of this assignment
> pchars^ := chars;
> ^^^^^
> This expression has type ARRAY OF CHAR
obc's message is very nice ;-)
A side issue is that I cannot find another way to return an array or a record other than via a pointer. Meaning eg a Text type would actually need to be a type of pointers to actual string data. But pointers break clear and secure value semantics, in that after
t2 := t1;
any change to either text affects both. One is thus forced to explicitely dereference all string variables:
t2^ := t1^;
I also find myself forced to build the string data self as a record to be able to affect it various needed methods. So, I end up as of now with the following:
TYPE
Chars = ARRAY OF CHAR;
PChars = POINTER TO Chars;
DText = RECORD (* actual text data *)
pchars : PChars;
count : LONGINT;
isEmpty : BOOLEAN;
END;
Text = POINTER TO DText;
But I'm blocked, as explained above, in assigning pchars^ at creation of a Text.
denis
________________________________
vit esse estrany ☣
spir.wikidot.com
More information about the Oberon
mailing list