summaryrefslogtreecommitdiffhomepage
path: root/include/stc
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-09-25 21:48:33 +0200
committerTyge Løvset <[email protected]>2022-09-25 21:48:33 +0200
commitad5be4349232bbba96c0974bc2693ec7331c4b12 (patch)
treeb214b16c14c3616a43d3a7d3b1816551d7d4b7cf /include/stc
parent6a44675dbcc5f82d1edeb07b5067532da8ef57ac (diff)
downloadSTC-modified-ad5be4349232bbba96c0974bc2693ec7331c4b12.tar.gz
STC-modified-ad5be4349232bbba96c0974bc2693ec7331c4b12.zip
Added i.size to c_forlist() macro + example.
Diffstat (limited to 'include/stc')
-rw-r--r--include/stc/ccommon.h11
1 files changed, 5 insertions, 6 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 02f41dd5..2b3cfd76 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -163,7 +163,7 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle,
; it.ref != (C##_value*)_endref; C##_next(&it))
#ifndef c_FLT_STACK
-#define c_FLT_STACK 20
+#define c_FLT_STACK 16
#endif
#define c_flt_take(i, n) (++(i).stack[(i).top++] <= (n))
#define c_flt_drop(i, n) (++(i).stack[(i).top++] > (n))
@@ -206,8 +206,8 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle,
typedef long long crange_value;
struct {crange_value val, end, step; } typedef crange;
struct {crange_value *ref, end, step; } typedef crange_iter;
-#define crange_from(...) c_MACRO_OVERLOAD(crange_from, __VA_ARGS__)
#define crange_init() crange_from3(0, INTMAX_MAX, 1)
+#define crange_from(...) c_MACRO_OVERLOAD(crange_from, __VA_ARGS__)
#define crange_from1(start) crange_from3(start, INTMAX_MAX, 1)
#define crange_from2(start, end) crange_from3(start, end, 1)
STC_INLINE crange crange_from3(crange_value start, crange_value finish, crange_value step)
@@ -220,10 +220,9 @@ STC_INLINE void crange_next(crange_iter* it)
{ *it->ref += it->step; if ((it->step > 0) == (*it->ref > it->end)) it->ref = NULL; }
#define c_forlist(it, T, ...) \
- for (struct {T* data; T* ref; size_t index;} \
- it = {.data=(T[])__VA_ARGS__, .ref=it.data} \
- ; it.ref != &it.data[c_arraylen(((T[])__VA_ARGS__))] \
- ; ++it.ref, ++it.index)
+ for (struct {T* data; T* ref; int size, index;} \
+ it = {.data=(T[])__VA_ARGS__, .ref=it.data, .size=c_arraylen(((T[])__VA_ARGS__))} \
+ ; it.index < it.size; ++it.ref, ++it.index)
#define c_with(...) c_MACRO_OVERLOAD(c_with, __VA_ARGS__)
#define c_with2(declvar, drop) for (declvar, **_c_i = NULL; !_c_i; ++_c_i, drop)