← Back to davo.co
aboutsummaryrefslogtreecommitdiffstats
path: root/array_or_struct.c
blob: 3190fe1a9d3a4ea459b38e36955cd852fffa79ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdio.h>

#ifdef USE_STRUCT
  typedef struct two two;
  struct two { double e1; double e2; };
# define FRST(X) ((X).e1)
# define SEC(X) ((X).e2)
#else
  typedef double two[2];
# define FRST(X) ((X)[0])
# define SEC(X) ((X)[1])
#endif

void func0(void) {
  for (two sp = { 1, 1, };
       FRST(sp) + SEC(sp) < 10;
       FRST(sp) += SEC(sp)) {
    printf("two values %g %g\n", FRST(sp), SEC(sp));
    SEC(sp) += (FRST(sp) + SEC(sp))/2;
  }
}

void func1(void) {
  for (register two sp = { 1, 1, };
       FRST(sp) + SEC(sp) < 10;
       FRST(sp) += SEC(sp)) {
    printf("two values %g %g\n", FRST(sp), SEC(sp));
    SEC(sp) += (FRST(sp) + SEC(sp))/2;
  }
}