Re: Exported pointer variables
Posted: Thu Oct 11, 2012 7:55 am
Uhm, I don't get your interpretation, then you consider public field identifers in a record as read only variables?
A technical support group for Astrobe Oberon users
http://www.astrobe.com/forum/
4. Declarations and Scope Rules
[...]
Variables and record fields marked with a minus in their declaration are read-only in importing modules.
My interpretation is still that exported record fields in Oberon-07/11 are always read-write, also if they are part of a variable declared in the module's scope (like in the first example of augustk).4. Declarations and Scope Rules
[...]
Variables and record fields marked with " - " in their declaration are read-only (variables and fields) or implement-only (methods) in importing modules.
Code: Select all
MODULE M;
TYPE
T* = POINTER TO RECORD
x*: INTEGER
END;
VAR t*: T;
PROCEDURE* Setx*(x: INTEGER);
BEGIN
t.x := x
END Setx;
BEGIN
NEW(t);
t.x := 0;
...
...
instead of:Variables are always exported in read-only mode.
Array and Record variables can be exported in read-only mode In Astrobe for Cortex-M3 v5.0 and later.Variables cannot be exported, with the exception of those of scalar types in read-only mode.
This is good news, at least for non-pointer variables. It implies that each exported constant can be changed to an exported variable (if its value needs to be computed at run-time) without changing the client modules. Before we could not export character arrays, for instance.Variables are always exported in read-only mode.
Code: Select all
MODULE M;
TYPE T* = POINTER TO RECORD x*: INTEGER END;
VAR
p*: T;
q*: POINTER TO RECORD x*: INTEGER END;
END M.
The way we have implemented this feature in the upcoming v5.1 of Astrobe the following code results in Error: read-only for all five of the following assignments:augustk wrote:The semantics of exported pointer variables is subtle though. Consider the following module:
In a client module the field M.p.x can be modified by a variable of type M.T whereas the field M.q.x cannot be modified.Code: Select all
MODULE M; TYPE T* = POINTER TO RECORD x*: INTEGER END; VAR p*: T; q*: POINTER TO RECORD x*: INTEGER END; END M.
Code: Select all
VAR
p: M.T;
BEGIN
NEW(M.p);
NEW(M.q);
M.p.x := 0;
M.p := p;
M.q.x := 0;
Code: Select all
p := M.p;
p.x := 0;