| 1 |
(* conststrarray.mod provides a test to access a constant array. |
| 2 |
|
| 3 |
Copyright (C) 2020 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
You should have received a copy of the GNU General Public License |
| 19 |
along with GNU Modula-2; see the file COPYING3. If not see |
| 20 |
<http://www.gnu.org/licenses/>. *) |
| 21 |
|
| 22 |
MODULE conststrarray ; |
| 23 |
|
| 24 |
FROM libc IMPORT exit, printf ; |
| 25 |
FROM SYSTEM IMPORT SIZE, ADR ; |
| 26 |
|
| 27 |
TYPE |
| 28 |
array = ARRAY [0..26] OF CHAR ; |
| 29 |
|
| 30 |
CONST |
| 31 |
str = array { "A", "B", "C", "D", "E", "F", "G", "H", |
| 32 |
"I", "J", "K", "L", "M", "N", "O", "P", |
| 33 |
"Q", "R", "S", "T", "U", "V", "W", "X", |
| 34 |
"Y", "Z" } ; |
| 35 |
|
| 36 |
PROCEDURE assert (b: BOOLEAN; file: ARRAY OF CHAR; line: CARDINAL) ; |
| 37 |
BEGIN |
| 38 |
IF NOT b |
| 39 |
THEN |
| 40 |
printf ("%s:%d:assert failed\n", ADR (file), line) ; |
| 41 |
r := 1 |
| 42 |
END |
| 43 |
END assert ; |
| 44 |
|
| 45 |
|
| 46 |
VAR |
| 47 |
s: array ; |
| 48 |
c: CARDINAL ; |
| 49 |
r: INTEGER ; |
| 50 |
BEGIN |
| 51 |
r := 0 ; |
| 52 |
s := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; |
| 53 |
FOR c := 0 TO 25 DO |
| 54 |
printf ("c = %d, s[c] = %c, str[c] = %c, %c\n", c, s[c], str[c], CHR (ORD ('A')+c)) ; |
| 55 |
assert (s[c] = CHR (ORD ('A')+c), __FILE__, __LINE__) ; |
| 56 |
assert (s[c] = str[c], __FILE__, __LINE__) |
| 57 |
END ; |
| 58 |
exit (r) |
| 59 |
END conststrarray. |