[Oberon] open array usage
Chris Burrows
chris at cfbsoftware.com
Sun Jul 11 03:57:09 MEST 2010
>From: oberon-bounces at lists.inf.ethz.ch
>[mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
>Aubrey.McIntosh at Alumni.UTexas.Net
>Sent: Sunday, 11 July 2010 10:56 AM
>
>In reading the compiler and system source, I have seen
>statements of the form
>
> InitStruct (s1, "this", 42, "that");
> InitStruct (s2, "another", 43, "item");
> InitStruct (s3, "more", 44, "again")
>
Yes - that is a good example of the general case where the array is an array
of something other than a basic type.
I have seen a similar 'divide and conquer' approach used when
a) the array is an array of a basic type
b) there are a large number of items
c) there is no discernible sequence or pattern allowing loop initialisation
to be used
e.g. r: ARRAY 200 OF REAL;
The 'helper' procedure looks like:
PROCEDURE Init(VAR r: ARRAY OF REAL; offset: INTEGER; d0, d1, d2, d3, d4,
d5, d6, d7, d8, d9: REAL);
BEGIN
r[offset] := d0;
r[offset+1] := d1;
...
END Init;
and the initialisation sequence is then something like:
Init(r, 0, 1.0, 3.0, 5.0, 7.0, 9.0, 2.0, 4.0, 4.1, 2.1, 4.3);
Init(r, 10, 11.0, 31.0, 15.0, 27.0, 91.0, 42.0, 34.0, 24.1, 12.1, 34.3);
Init(r, 20, 11.1, 31.6, 14.0, 21.0, 31.0, 42.6, 31.0, 20.1, 11.1, 30.3);
....
....
Init(r,190, 11.0, 31.0, 15.0, 27.0, 91.0, 42.0, 4.0, 4.1, 2.1, 4.3);
What might otherwise have been 200 statements is reduced to 30 statements.
However, in many cases where you have a large number of constant values used
for initialisation the numbers are read in from a file, a registry, a
resource etc. etc. rather than being hard-coded constants.
Regards,
Chris Burrows
CFB Software
Astrobe: ARM Oberon-07 Development System
http://www.astrobe.com
More information about the Oberon
mailing list