On Sunday, March 22, 2020 at 5:57:30 AM UTC+10:30, Guy T. wrote:
Hello again,
The Project Oberon compiler allows for a definition as follow:
VAR a: ARRAY 0 OF CHAR;
Is there a useful case for defining a zero length array? I can't see any.
I don't recall ever making use of it myself but I can think of a possible scenario where it could be useful:
Oberon does not allow optional parameters to procedures. Just suppose you wanted to implement a procedure that generally took an array as a parameter but there were situations where it was not needed. If you could not create a zero array it would not be
quite as clear to the reader that it is to be ignored. e.g. something like this:
VAR
null: ARRAY 0 OF INTEGER;
values: ARRAY 10 OF INTEGER;
i: INTEGER;
PROCEDURE P(i: INTEGER; a: ARRAY OF INTEGER);
BEGIN
IF LEN(a) > 0 THEN ...
END P;
BEGIN
P(i, null);
P(i, values);
...
...
P.S. I'm not necessarily recommending this practice ;-)
Cheers,
Chris
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)