[Oberon] Dynamic array allocation?
Till Oliver Knoll
till.oliver.knoll at gmail.com
Tue Apr 9 08:18:06 CEST 2019
I suspect that this question has been asked a couple of times already,
but I found multiple answers which kind of contradict each other.
Can I dynamically allocate memory (on the heap) for arrays, at least for
arrays of "built in types" such as INTEGER, BYTE and the like?
I stumbled via
Chapter 19. Dynamic Arrays:
"Dynamic arrays are here introduced as an addition to Oberon. An array
is called dynamic, if its length is determined “dynamically”, i.e. at
execution time. This is done by a call to the intrinsic procedure NEW
with a second parameter indicating the desired length. Example:
VAR a: ARRAY OF INTEGER;
BEGIN ... NEW(a, len) ...
However when I try this in my "Oberon Core" (as found in the Mac App
Store, based on Project Oberon 2013) I get an "expression expected"
syntax error at the location of "ARRAY OF INTEGER": the compiler in use
still seems to expect a constant size declaration here.
So is this a feature specific to (some version of) the ARM compiler, as
used by Professor Wirth for his FPGA Oberon?
Then I also found
"This procedure can be used, if the user has not adopted the enhanced
Oberon runtime system and Oberon-07 compiler provided in
which implements a predefined procedure NEW(p, len) for dynamic open
arrays (in Experimental Oberon, it is implemented by default)."
This also seems to support the theory that the "plain vanilla compiler"
does not support dynamic allocation with NEW(pointer, size)?
In other words: I need to "upgrade" my Oberon compiler (somehow) such
that I can dynamically allocate (simple) arrays?
More information about the Oberon