Chalmers@europarc.xerox.com (Matthew Chalmers) (01/26/91)
Hi - Concatenated below are a number of files which collectively show something I don't understand with passing arrays to a procedure in a module. The difference seems to be whether arrays are passed as open or of fixed length (c.f. foo.proc1 and foo.proc2). The output of the collected code is just below, and this shows the wierdness: only 3 longreals copied across(?) instead of 6. Main: 1 2 3 4 9 8 proc1 1 2 3 4 9 8 proc2 1 2 3 4.55779D-309 4.24399D-314 1.37939D-318 I had expected proc2 to output the same thing as proc1. Regards, Matthew Chalmers (*-------------------- cut here -------------------- *) INTERFACE foo; TYPE TwoVec = ARRAY [0..1] OF LONGREAL; PROCEDURE proc1 (p : ARRAY [0..2] OF TwoVec); PROCEDURE proc2 (p : ARRAY OF TwoVec); END foo. MODULE foo; IMPORT Wr, Stdio, Fmt; PROCEDURE proc1 (p : ARRAY [0..2] OF TwoVec) = BEGIN Wr.PutText(Stdio.stdout,"\nproc1\n"); FOR i := 0 TO NUMBER(p)-1 DO Wr.PutText(Stdio.stdout," " & Fmt.LongReal(p[i][0])); Wr.PutText(Stdio.stdout," " & Fmt.LongReal(p[i][1]) & "\n"); END; END proc1; PROCEDURE proc2 (p : ARRAY OF TwoVec) = BEGIN Wr.PutText(Stdio.stdout,"\nproc2\n"); FOR i := 0 TO NUMBER(p)-1 DO Wr.PutText(Stdio.stdout," " & Fmt.LongReal(p[i][0])); Wr.PutText(Stdio.stdout," " & Fmt.LongReal(p[i][1]) & "\n"); END; END proc2; BEGIN END foo. MODULE Main; IMPORT Wr, Stdio, Fmt; IMPORT foo; VAR points : ARRAY [0..2] OF foo.TwoVec; VAR x, y : LONGREAL; BEGIN x := 1.0d0; y := 2.0d0; Wr.PutText(Stdio.stdout, "Main:\n"); FOR i := 0 TO 2 DO points[i][0] := x; points[i][1] := y; Wr.PutText(Stdio.stdout, " " & Fmt.LongReal(x)); Wr.PutText(Stdio.stdout, " " & Fmt.LongReal(y) & "\n"); x := x * 3.0d0; y := y * 2.0d0; END; foo.proc1 (points); foo.proc2 (points); END Main.
Chalmers@europarc.xerox.com (Matthew Chalmers) (01/26/91)
Umm... forgot to say we are using m3 v.1.5. --mjc
harrison@darwin.pa.dec.com (Stephen Harrison) (01/26/91)
Matthew Chalmers reported a problem with 2-D arrays in SRC Modula-3, v1.5. I tried his example with SRC Modula-3, v1.6beta and it works fine. Regards, /Stephen -- Stephen Harrison | harrison@decwse.dec.com Advanced Technology Development | Digital Equipment Corporation | work (415) 853-6747 100 Hamilton Avenue, Palo Alto, CA 94301 | home (408) 739-7734