summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-03-25 07:35:21 +0100
committerTyge Løvset <[email protected]>2022-03-25 07:35:21 +0100
commitf943c8b7a6e46dc002ffc63c9fbcc111f6dca55d (patch)
tree32a315540d058ca5968f05caa973411c13f8226d
parentfb1f2f3dcec3acf10fcd9f6674fbddb3fd682b3c (diff)
downloadSTC-modified-f943c8b7a6e46dc002ffc63c9fbcc111f6dca55d.tar.gz
STC-modified-f943c8b7a6e46dc002ffc63c9fbcc111f6dca55d.zip
Modified (more) rarely used macros c_apply_cnt(v, ..) and c_apply_arr(v, ..) so that v is a reference that may modify the container items.
-rw-r--r--examples/cpque.c4
-rw-r--r--examples/inits.c4
-rw-r--r--include/stc/ccommon.h8
3 files changed, 8 insertions, 8 deletions
diff --git a/examples/cpque.c b/examples/cpque.c
index 048d9b51..8a3564f0 100644
--- a/examples/cpque.c
+++ b/examples/cpque.c
@@ -37,11 +37,11 @@ int main()
print_queue(q);
icmp_fn = imin_cmp;
- c_apply_arr(v, ipque_push(&q2, v), const int, data, n);
+ c_apply_arr(v, ipque_push(&q2, *v), const int, data, n);
print_queue(q2);
icmp_fn = imix_cmp;
- c_apply_arr(v, ipque_push(&q3, v), const int, data, n);
+ c_apply_arr(v, ipque_push(&q3, *v), const int, data, n);
print_queue(q3);
}
}
diff --git a/examples/inits.c b/examples/inits.c
index 78eced11..3bd7e3b4 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -37,11 +37,11 @@ int main(void)
// CVEC FLOAT / PRIORITY QUEUE
c_auto (cpque_f, floats) {
- float nums[] = {4.0f, 2.0f, 5.0f, 3.0f, 1.0f};
+ const float nums[] = {4.0f, 2.0f, 5.0f, 3.0f, 1.0f};
// PRIORITY QUEUE
- c_apply_arr(v, cpque_f_push(&floats, v), float, nums, c_arraylen(nums));
+ c_apply_arr(v, cpque_f_push(&floats, *v), const float, nums, c_arraylen(nums));
puts("\npop and show high priorites first:");
while (! cpque_f_empty(floats)) {
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 4034c0ce..4ee6cad0 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -200,14 +200,14 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle, size_t slen, cons
} while (0)
#define c_apply_arr(v, action, T, arr, n) do { \
typedef T _c_T; \
- const _c_T* _c_arr = arr; size_t _n = n; \
- for (size_t index = 0; index < _n; ++index) \
- { const _c_T v = _c_arr[index]; action; } \
+ _c_T *_c_arr = arr; \
+ for (size_t index = 0, _c_n = n; index < _c_n; ++index) \
+ { _c_T *v = _c_arr + index; action; } \
} while (0)
#define c_apply_cnt(v, action, C, ...) do { \
size_t index = 0; \
c_foreach (_it, C, __VA_ARGS__) \
- { const C##_value v = *_it.ref; action; ++index; } \
+ { C##_value* v = _it.ref; action; ++index; } \
} while (0)
#define c_pair(v) (v).first, (v).second