aboutsummaryrefslogtreecommitdiff
path: root/lib/cbit/misc.h
blob: 45876f9d30e17e4ac53b5d6b008c8e1b2df327a3 (plain) (blame)
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
#pragma once

#define LET_LOOP__(expr, ctr) \
   if (0) \
      __done_##ctr: continue; \
   else if (0) \
      __break_##ctr: break; \
   else \
      for (; ; ({ goto __break_##ctr; })) \
         for (expr; ; ({ goto __done_##ctr; }))

#define LET_LOOP_(expr, ctr) LET_LOOP__(expr, ctr)
#define LET_LOOP(expr) LET_LOOP_(expr, __COUNTER__)

#define LET__(expr, ctr) \
   if (0) \
      __done_##ctr: ; \
   else \
      for (expr; ; ({ goto __done_##ctr; }))

#define LET_(expr, ctr) LET__(expr, ctr)
#define LET(expr) LET_(expr, __COUNTER__)

#define safe_mul(a, b) ((a) * (b)) /* XXX */