Systemnahe Programmierung in C: Mehrdimensionale Felder |
1long f1 (long ar[][6][7]);
2long f2 (long *, unsigned, unsigned, unsigned);
3
4void
5test (void)
6{
7 long x;
8 long larray[5][6][7];
9
10 x = f1 (larray);
11
12 x = f2 (&larray[0][0][0], 5, 6, 7);
13
14}
15
16long
17f1 (long ar[][6][7])
18{
19 return ar[1][2][3];
20}
21
22long
23f2 (long *ar, unsigned d1, unsigned d2, unsigned d3)
24{
25 return *(ar + 1 * d3 * d2 + 2 * d2 + 3);
26
27 /* oder */
28
29 return ar[1 * d3 * d2 + 2 * d2 + 3];
30
31 /* oder */
32
33 return ar[(1 * d3 + 2) * d2 + 3];
34
35}
|
1#include <stdio.h>
2
3enum TYPES
4{ SPECIAL = -2,
5 ILLEGAL,
6 INT,
7 FLOAT,
8 DOUBLE,
9 POINTER,
10 LAST
11};
12
13enum TYPES result_type[LAST][LAST] =
14{ INT, DOUBLE, DOUBLE, POINTER,
15 DOUBLE, DOUBLE, DOUBLE, ILLEGAL,
16 DOUBLE, DOUBLE, DOUBLE, ILLEGAL,
17 POINTER, ILLEGAL, ILLEGAL, SPECIAL
18};
19
20enum TYPES
21type_needed (enum TYPES t1, enum TYPES t2)
22{
23 enum TYPES result = result_type[t1][t2];
24
25 if (result == ILLEGAL)
26 fprintf (stderr, "Illegal Operands\n");
27
28 return result;
29}
|
1#include <stdio.h>
2
3typedef enum
4{ SPECIAL = -2,
5 ILLEGAL,
6 INT,
7 FLOAT,
8 DOUBLE,
9 POINTER,
10 LAST
11}
12TYPES;
13
14TYPES result_type[LAST][LAST] =
15 { { INT, DOUBLE, DOUBLE, POINTER },
16 { DOUBLE, DOUBLE, DOUBLE, ILLEGAL },
17 { DOUBLE, DOUBLE, DOUBLE, ILLEGAL },
18 { POINTER, ILLEGAL, ILLEGAL, SPECIAL }
19 };
20
21TYPES
22type_needed (TYPES t1, TYPES t2)
23{
24 TYPES result = result_type[t1][t2];
25
26 if (result == ILLEGAL)
27 fprintf (stderr, "Illegal Operands\n");
28
29 return result;
30}
|
Letzte Änderung: 11.01.2007 | © Prof. Dr. Uwe Schmidt |