summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-05-21 14:55:04 +0200
committerTyge Løvset <[email protected]>2021-05-21 14:55:04 +0200
commit345bff3cc9a36135a00bb963b3fada09d054980d (patch)
tree69487c6e9e156e4fc01cb5445c776803f919ee9d /include
parent141c31a725ef0509998b208f4dda897347cbe4f2 (diff)
downloadSTC-modified-345bff3cc9a36135a00bb963b3fada09d054980d.tar.gz
STC-modified-345bff3cc9a36135a00bb963b3fada09d054980d.zip
Allow up to 3 vars in the c_withvar (type, v1, v2, v3) statement.
Diffstat (limited to 'include')
-rw-r--r--include/stc/ccommon.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index d29ce699..2bc45a21 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -122,9 +122,13 @@
for (type i=start, _c_inc=step, _c_end=(stop) - (0 < _c_inc) \
; (i <= _c_end) == (0 < _c_inc); i += _c_inc)
-#define c_defer(...) for (int _c_ii = 0; !_c_ii; ++_c_ii, __VA_ARGS__)
#define c_with(start, end) for (start, *_c_ii = NULL; !_c_ii; ++_c_ii, end)
-#define c_withvar(ctype, var) c_with (ctype var = ctype##_init(), ctype##_del(&var))
+#define c_withvar(...) c_MACRO_OVERLOAD(c_withvar, __VA_ARGS__)
+#define c_withvar_2(CX, var) c_with (CX var = CX##_init(), CX##_del(&var))
+#define c_withvar_3(CX, v1, v2) c_with (_c_EXPAND(CX v1 = CX##_init(), v2 = v1), (CX##_del(&v2), CX##_del(&v1)))
+#define c_withvar_4(CX, v1, v2, v3) c_with (_c_EXPAND(CX v1 = CX##_init(), v2 = v1, v3 = v1), \
+ (CX##_del(&v3), CX##_del(&v2), CX##_del(&v1)))
+#define c_defer(...) for (int _c_ii = 0; !_c_ii; ++_c_ii, __VA_ARGS__)
#define c_withbuf(b, type, n) c_withbuf_N(b, type, n, 256)
#define c_withbuf_N(b, type, n, BYTES) \