Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!elroy.jpl.nasa.gov!decwrl!pa.dec.com!src.dec.com!Matthew Chalmers From: Chalmers@europarc.xerox.com (Matthew Chalmers) Newsgroups: comp.lang.modula3 Subject: oddness with 2-d arrays Message-ID: <8bc6zicB0Tlj05F1Y8@sparky.EuroPARC.Xerox.COM> Date: 25 Jan 91 17:50:38 GMT Lines: 93 To: m3 Cc: Matthew Chalmers 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.