[Oberon] Initial value of variables, where specified?
Chris Burrows
chris at cfbsoftware.com
Wed Feb 12 02:06:12 CET 2020
The value a variable is supposed to have before it is explicitly assigned a
value is not defined in the latest Oberon Language Report.
In Project Oberon dynamic variables are initialised to zero when they are
allocated by NEW. The relevant code is in Kernel.New:
WHILE p < lim DO SYSTEM.PUT(p, 0); INC(p, 4) END
Regards,
Chris Burrows
CFB Software
https://www.astrobe.com
> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> rochus.keller at bluewin.ch
> Sent: Wednesday, 12 February 2020 10:40 AM
> To: oberon at lists.inf.ethz.ch
> Subject: [Oberon] Initial value of variables, where specified?
>
> What value is a variable supposed to have before it is explicitly
> assigned a value?
>
> E.g. in MenuViewer.Mod line 205 I found at projectoberon.com there is
> a call of Viewers.Open(V, X, Y) where V is of type Viewer and NEW(V)
> is called on line 203. In Viewers.Open V.state is accessed for the
> first time; there was no explicit assignment to V.state before (at
> least I didn't see one). Since the code works I assume that V.state
> is automatically initialized to zero by the generated code.
>
> Where is this behaviour specified? I looked through different
> language report versions and books but didn't find a clear answer
> yet.
> Is it the same for all variable types, e.g. also for arrays? If I
> e.g. declare VAR a: ARRAY10 OF INTEGER, are the elements of a
> supposed to be zero when the module is loaded (i.e. before the
> statement sequence is executed)?
>
> Best
> R.
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related
> systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
More information about the Oberon
mailing list