This is probably a silly question, but how can I create a function to print an array? Obviously I'd use a FOR loop over the elements, but when I try to use something like: VAR a: ARRAY 10 OF INTEGER; PROCEDURE PrintArray(VAR a: ARRAY OF INTEGER); VAR i: INTEGER; BEGIN FOR i := 0 TO LEN(a) - 1 DO Out.Int(a[i], 0); Out.String(" "); END; END PrintArray; I get the error: /home/martin/code/Oberon/Bogo.Mod:32:30: Expression not compatible with variable type `INTEGER' Which I assume means LEN can't get the length of a?
Martin Bishop wrote:
PROCEDURE PrintArray(VAR a: ARRAY OF INTEGER); VAR i: INTEGER; BEGIN FOR i := 0 TO LEN(a) - 1 DO Out.Int(a[i], 0); Out.String(" "); END; END PrintArray;
That appears correct to me and my compiler. Which Compiler do you use? OOC?
/home/martin/code/Oberon/Bogo.Mod:32:30: Expression not compatible with variable type `INTEGER'
Assuming that 32:30 means line 32 pos 30 please show us the complete code and location of the error.
Which I assume means LEN can't get the length of a?
I don't think so. Greetings, Christian
Am Dienstag, den 07.10.2008, 15:05 -0500 schrieb Martin Bishop:
This is probably a silly question, but how can I create a function to print an array? [...]
I get the error:
Depending on your compiler/system type of LEN(a) may be LONGINT. You may try VAR i: LONGINT; or SHORT(LEN(a)).
Stefan Salewski wrote:
Am Dienstag, den 07.10.2008, 15:05 -0500 schrieb Martin Bishop:
This is probably a silly question, but how can I create a function to print an array? [...] I get the error:
Depending on your compiler/system type of LEN(a) may be LONGINT. You may try VAR i: LONGINT; or SHORT(LEN(a)).
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Yep, both solutions worked, although the weird thing is typically the compiler doesn't complain. And yes I use OO2C. Thanks for the help!
participants (3)
-
chris@gcjd.de-web.ws -
Martin Bishop -
Stefan Salewski