source: Deliverables/D2.2/8051/tests/tmp_tests/Backend/struct_and_ptr_and_fact_u.c @ 1525

Last change on this file since 1525 was 1525, checked in by ayache, 9 years ago

D2.2: function pointers using JMP.

File size: 522 bytes
Line 
1
2typedef struct foo {
3  unsigned char dummy;
4  unsigned char x;
5} foo;
6
7foo *p;
8foo save;
9
10unsigned char fact1 (unsigned char x) {
11  if (x <= 1) return 1;
12  return (x * fact1(x-1));
13}
14
15unsigned char fact2 (unsigned char x) {
16  unsigned char i, res = 1;
17
18  for (i = 1 ; i <= x ; i++)
19    res *= i;
20
21  return res;
22}
23
24unsigned 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_uchar((*(q[1])).x == y.x);
37  newline();
38
39  return 0;
40}
Note: See TracBrowser for help on using the repository browser.