aboutsummaryrefslogtreecommitdiff
path: root/2026-linuxdays/simple.c
blob: 75c5de295de25d9c77f6b09864a3e41721983aaa (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
31
#define CHAR_BIT 8

unsigned loop(unsigned x) {
  while (x > 0)
    x--;
  return x;
}

int add2(int a, int b) { return a + b; }
int add9(int a, int b, int c, int d, int e, int f, int g, int h, int i) {
  return a + b + c + d + e + f + g + h + i;
}

void call_add(void) {
  add2(1, 2);
  add9(1, 2, 3, 4, 5, 6, 7, 8, 9);
}

struct px {
  int x, y;
};
int x_plus_y(struct px *p) { return p->x + p->y; }

int div2_a(unsigned x) { return x / 2; }
int div2_b(unsigned x) { return x >> 1; }

int abs_a(int x) { return x < 0 ? -x : x; }
int abs_b(int x) {
  int m = x >> (sizeof(x) * CHAR_BIT - 1);
  return (x + m) ^ m;
}