Last change
on this file since 1525 was
1525,
checked in by ayache, 9 years ago
|
D2.2: function pointers using JMP.
|
File size:
506 bytes
|
Line | |
---|
1 | |
---|
2 | typedef struct foo { |
---|
3 | signed char dummy; |
---|
4 | signed char x; |
---|
5 | } foo; |
---|
6 | |
---|
7 | foo *p; |
---|
8 | foo save; |
---|
9 | |
---|
10 | signed char fact1 (signed char x) { |
---|
11 | if (x <= 1) return 1; |
---|
12 | return (x * fact1(x-1)); |
---|
13 | } |
---|
14 | |
---|
15 | signed char fact2 (signed char x) { |
---|
16 | signed char i, res = 1; |
---|
17 | |
---|
18 | for (i = 1 ; i <= x ; i++) |
---|
19 | res *= i; |
---|
20 | |
---|
21 | return res; |
---|
22 | } |
---|
23 | |
---|
24 | signed char main () { |
---|
25 | foo x, y; |
---|
26 | foo* q[3]; |
---|
27 | |
---|
28 | x.x = 5; |
---|
29 | |
---|
30 | q[1] = &x; |
---|
31 | p = &x; |
---|
32 | save = x; |
---|
33 | x.x = fact1(save.x); |
---|
34 | y.x = fact2(save.x); |
---|
35 | |
---|
36 | print_schar((*(q[1])).x == y.x); |
---|
37 | newline(); |
---|
38 | |
---|
39 | return 0; |
---|
40 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.