[M3devel] Array indexing
Dariusz Knociński
dknoto at next.com.pl
Thu Dec 30 20:09:53 CET 2010
Hi all,
my name is Dariusz Knociński, I am new in this list, it is my first letter.
Best wishes for New Year to all.
I have a problem with two-dimensional arrays. In my simple source code I can't
get value from array indexed by two variables. But, I can get these values by
indexing by constants. The program compile successfully but generates idiotic
output.
Source:
MODULE aib EXPORTS Main;
IMPORT IO, Fmt;
CONST
tab = ARRAY [0..2], [0..15] OF CARDINAL {
ARRAY OF CARDINAL
{ 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17 },
ARRAY OF CARDINAL
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 17, 17, 17, 17, 17, 17 },
ARRAY OF CARDINAL
{ 17, 11, 12, 13, 14, 15, 16, 17, 17, 17, 17, 17, 17, 17, 17, 17 }
};
VAR
k, l : CARDINAL;
BEGIN
k := 1;
l := 9;
IO.Put( "k = " & Fmt.Int(k) & ", " );
IO.Put( "l = " & Fmt.Int(l) & "\n" );
k := tab[k][l];
IO.Put( "k = tab[k][l] => 0x" &
Fmt.F( "%02s", Fmt.Unsigned(k)) & "\n" );
k := tab[1][9];
IO.Put( "k = tab[1][9] => 0x" &
Fmt.F( "%02s", Fmt.Unsigned(k)) & "\n" );
FOR i := 0 TO 2 DO
FOR j := 0 TO 15 DO
IO.Put( Fmt.F( " %02s", Fmt.Int( tab[i][j] ) ) );
END;
IO.Put( "\n" );
END;
END aib.
Output:
k = 1, l = 9
k = tab[k][l] => 0x00
k = tab[1][9] => 0x0a
6296864 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00
6296864 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00
6296864 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00
My system and compiler version is:
$ uname -a
Linux wenus.next.com.pl 2.6.35.10-74.fc14.x86_64 #1 SMP Thu Dec 23 16:04:50\
UTC 2010 x86_64 x86_64 x86_64 GNU/Linux
$ cm3 -version
Critical Mass Modula-3 version 5.8.6
last updated: 2010-04-11
compiled: 2010-07-12 20:10:34
configuration: /usr/local/cm3/bin/cm3.cfg
host: AMD64_LINUX
target: AMD64_LINUX
or
Critical Mass Modula-3 version d5.9.0
last updated: 2010-07-21
compiled: 2010-12-16 03:15:26
configuration: /usr/local/cm3/bin/cm3.cfg
host: AMD64_LINUX
quake runtime error: "/usr/local/cm3/bin/cm3.cfg", line 2: quake runtime error:\
undefined variable: SL
--procedure-- -line- -file---
2 /usr/local/cm3/bin/cm3.cfg
target:
Both compilers generate same results.
Best regards
DKnoto.
More information about the M3devel
mailing list