summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--benchmarks/plotbench/cdeq_benchmark.cpp4
-rw-r--r--benchmarks/plotbench/clist_benchmark.cpp4
-rw-r--r--benchmarks/plotbench/cmap_benchmark.cpp4
-rw-r--r--benchmarks/plotbench/cpque_benchmark.cpp4
-rw-r--r--benchmarks/plotbench/csmap_benchmark.cpp4
-rw-r--r--benchmarks/plotbench/cvec_benchmark.cpp4
-rw-r--r--docs/ccommon_api.md10
-rw-r--r--docs/clist_api.md2
-rw-r--r--docs/cregex_api.md4
-rw-r--r--examples/list.c2
-rw-r--r--examples/prime.c2
-rw-r--r--examples/stack.c4
-rw-r--r--include/stc/ccommon.h11
13 files changed, 30 insertions, 29 deletions
diff --git a/benchmarks/plotbench/cdeq_benchmark.cpp b/benchmarks/plotbench/cdeq_benchmark.cpp
index 42395778..49db3914 100644
--- a/benchmarks/plotbench/cdeq_benchmark.cpp
+++ b/benchmarks/plotbench/cdeq_benchmark.cpp
@@ -109,10 +109,10 @@ Sample test_stc_deque() {
int main(int argc, char* argv[])
{
Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1];
- c_forrange (int, i, SAMPLES) {
+ c_forrange (i, int, SAMPLES) {
std_s[i] = test_std_deque();
stc_s[i] = test_stc_deque();
- if (i > 0) c_forrange (int, j, N_TESTS) {
+ if (i > 0) c_forrange (j, int, N_TESTS) {
if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j];
if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j];
if (stc_s[i].test[j].sum != stc_s[0].test[j].sum) printf("Error in sum: test %d, sample %d\n", i, j);
diff --git a/benchmarks/plotbench/clist_benchmark.cpp b/benchmarks/plotbench/clist_benchmark.cpp
index fad44ed5..ddd1e2f0 100644
--- a/benchmarks/plotbench/clist_benchmark.cpp
+++ b/benchmarks/plotbench/clist_benchmark.cpp
@@ -106,10 +106,10 @@ Sample test_stc_forward_list() {
int main(int argc, char* argv[])
{
Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1];
- c_forrange (int, i, SAMPLES) {
+ c_forrange (i, int, SAMPLES) {
std_s[i] = test_std_forward_list();
stc_s[i] = test_stc_forward_list();
- if (i > 0) c_forrange (int, j, N_TESTS) {
+ if (i > 0) c_forrange (j, int, N_TESTS) {
if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j];
if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j];
if (stc_s[i].test[j].sum != stc_s[0].test[j].sum) printf("Error in sum: test %d, sample %d\n", i, j);
diff --git a/benchmarks/plotbench/cmap_benchmark.cpp b/benchmarks/plotbench/cmap_benchmark.cpp
index b73f6bd1..cf20c927 100644
--- a/benchmarks/plotbench/cmap_benchmark.cpp
+++ b/benchmarks/plotbench/cmap_benchmark.cpp
@@ -113,10 +113,10 @@ Sample test_stc_unordered_map() {
int main(int argc, char* argv[])
{
Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1];
- c_forrange (int, i, SAMPLES) {
+ c_forrange (i, int, SAMPLES) {
std_s[i] = test_std_unordered_map();
stc_s[i] = test_stc_unordered_map();
- if (i > 0) c_forrange (int, j, N_TESTS) {
+ if (i > 0) c_forrange (j, int, N_TESTS) {
if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j];
if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j];
if (stc_s[i].test[j].sum != stc_s[0].test[j].sum) printf("Error in sum: test %d, sample %d\n", i, j);
diff --git a/benchmarks/plotbench/cpque_benchmark.cpp b/benchmarks/plotbench/cpque_benchmark.cpp
index 9e2f8d18..ca28082b 100644
--- a/benchmarks/plotbench/cpque_benchmark.cpp
+++ b/benchmarks/plotbench/cpque_benchmark.cpp
@@ -50,12 +50,12 @@ void stc_test()
printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
printf("%g ", *cpque_f_top(&pq));
- c_forrange (int, i, M) {
+ c_forrange (i, int, M) {
cpque_f_pop(&pq);
}
start = clock();
- c_forrange (int, i, M, N)
+ c_forrange (i, int, M, N)
cpque_f_pop(&pq);
printf("\npopped PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
}
diff --git a/benchmarks/plotbench/csmap_benchmark.cpp b/benchmarks/plotbench/csmap_benchmark.cpp
index 56a0e7d3..7e6d62c6 100644
--- a/benchmarks/plotbench/csmap_benchmark.cpp
+++ b/benchmarks/plotbench/csmap_benchmark.cpp
@@ -114,10 +114,10 @@ Sample test_stc_map() {
int main(int argc, char* argv[])
{
Sample std_s[SAMPLES + 1], stc_s[SAMPLES + 1];
- c_forrange (int, i, SAMPLES) {
+ c_forrange (i, int, SAMPLES) {
std_s[i] = test_std_map();
stc_s[i] = test_stc_map();
- if (i > 0) c_forrange (int, j, N_TESTS) {
+ if (i > 0) c_forrange (j, int, N_TESTS) {
if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j];
if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j];
if (stc_s[i].test[j].sum != stc_s[0].test[j].sum) printf("Error in sum: test %d, sample %d\n", i, j);
diff --git a/benchmarks/plotbench/cvec_benchmark.cpp b/benchmarks/plotbench/cvec_benchmark.cpp
index 62c4f9c8..a0faf679 100644
--- a/benchmarks/plotbench/cvec_benchmark.cpp
+++ b/benchmarks/plotbench/cvec_benchmark.cpp
@@ -105,10 +105,10 @@ Sample test_stc_vector() {
int main(int argc, char* argv[])
{
Sample std_s[SAMPLES + 1] = {{NULL}}, stc_s[SAMPLES + 1] = {{NULL}};
- c_forrange (int, i, SAMPLES) {
+ c_forrange (i, int, SAMPLES) {
std_s[i] = test_std_vector();
stc_s[i] = test_stc_vector();
- if (i > 0) c_forrange (int, j, N_TESTS) {
+ if (i > 0) c_forrange (j, int, N_TESTS) {
if (secs(std_s[i].test[j]) < secs(std_s[0].test[j])) std_s[0].test[j] = std_s[i].test[j];
if (secs(stc_s[i].test[j]) < secs(stc_s[0].test[j])) stc_s[0].test[j] = stc_s[i].test[j];
if (stc_s[i].test[j].sum != stc_s[0].test[j].sum) printf("Error in sum: test %d, sample %d\n", i, j);
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index 403d8ef9..c45dadc1 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -192,18 +192,18 @@ Declare an iterator and specify a range to iterate with a for loop. Like python'
|:----------------------------------------------|:-------------------------------------|
| `c_forrange (stop)` | `for _ in range(stop):` |
| `c_forrange (i, stop) // IntType = size_t` | `for i in range(stop):` |
-| `c_forrange (IntType, i, stop)` | `for i in range(stop):` |
-| `c_forrange (IntType, i, start, stop)` | `for i in range(start, stop):` |
-| `c_forrange (IntType, i, start, stop, step)` | `for i in range(start, stop, step):` |
+| `c_forrange (i, IntType, stop)` | `for i in range(stop):` |
+| `c_forrange (i, IntType, start, stop)` | `for i in range(start, stop):` |
+| `c_forrange (i, IntType, start, stop, step)` | `for i in range(start, stop, step):` |
```c
c_forrange (5) printf("x");
// xxxxx
c_forrange (i, 5) printf(" %" PRIuMAX "", i);
// 0 1 2 3 4
-c_forrange (int, i, -3, 3) printf(" %d", i);
+c_forrange (i, int, -3, 3) printf(" %d", i);
// -3 -2 -1 0 1 2
-c_forrange (int, i, 30, 0, -5) printf(" %d", i);
+c_forrange (i, int, 30, 0, -5) printf(" %d", i);
// 30 25 20 15 10 5
```
diff --git a/docs/clist_api.md b/docs/clist_api.md
index 1b3c5b0b..9927087d 100644
--- a/docs/clist_api.md
+++ b/docs/clist_api.md
@@ -114,7 +114,7 @@ int main() {
c_forlist (i, double, {10., 20., 30., 40., 50., 60., 70., 80., 90.})
DList_push_back(&list, *i.ref);
- c_forrange (int, i, 1, 10) {
+ c_forrange (i, int, 1, 10) {
if (i & 1) DList_push_front(&list, (double) i);
else DList_push_back(&list, (double) i);
}
diff --git a/docs/cregex_api.md b/docs/cregex_api.md
index 5f7e9136..2a0b22a8 100644
--- a/docs/cregex_api.md
+++ b/docs/cregex_api.md
@@ -128,13 +128,13 @@ To iterate multiple matches in an input string, you may use
```c
csview match[5] = {0};
while (cregex_find(&re, input, match, cre_m_next) == cre_success)
- c_forrange (int, k, cregex_captures(&re))
+ c_forrange (k, int, cregex_captures(&re))
printf("submatch %d: %.*s\n", k, c_ARGsv(match[k]));
```
There is also a safe macro which simplifies this:
```c
c_formatch (it, &re, input)
- c_forrange (int, k, cregex_captures(&re))
+ c_forrange (k, int, cregex_captures(&re))
printf("submatch %d: %.*s\n", k, c_ARGsv(it.match[k]));
```
diff --git a/examples/list.c b/examples/list.c
index 1f21304f..e94a9f18 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -17,7 +17,7 @@ int main() {
stc64_t rng = stc64_new(1234);
stc64_uniformf_t dist = stc64_uniformf_new(100.0f, n);
int m = 0;
- c_forrange (int, i, n)
+ c_forrange (n)
clist_fx_push_back(&list, stc64_uniformf(&rng, &dist)), ++m;
double sum = 0.0;
printf("sumarize %d:\n", m);
diff --git a/examples/prime.c b/examples/prime.c
index 7af66f33..d2a95af5 100644
--- a/examples/prime.c
+++ b/examples/prime.c
@@ -39,7 +39,7 @@ int main(void)
puts("");
int k = 20;
- c_forrange (intptr_t, i, n-1, 1, -2) {
+ c_forrange (i, intptr_t, n-1, 1, -2) {
if (k == 0) break;
else if (cbits_test(&primes, i>>1)) printf("%" PRIdMAX "\n", i), k--;
}
diff --git a/examples/stack.c b/examples/stack.c
index 210f8023..580b6428 100644
--- a/examples/stack.c
+++ b/examples/stack.c
@@ -14,12 +14,12 @@ int main() {
c_auto (cstack_i, stack)
c_auto (cstack_c, chars)
{
- c_forrange (int, i, 101)
+ c_forrange (i, int, 101)
cstack_i_push(&stack, i*i);
printf("%d\n", *cstack_i_top(&stack));
- c_forrange (int, i, 90)
+ c_forrange (i, int, 90)
cstack_i_pop(&stack);
c_foreach (i, cstack_i, stack)
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 59056905..08445dae 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -191,11 +191,12 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle,
; C##_next(&_._it))
#define c_forrange(...) c_MACRO_OVERLOAD(c_forrange, __VA_ARGS__)
-#define c_forrange1(stop) c_forrange4(size_t, _c_i, 0, stop)
-#define c_forrange2(i, stop) c_forrange4(size_t, i, 0, stop)
-#define c_forrange3(itype, i, stop) c_forrange4(itype, i, 0, stop)
-#define c_forrange4(itype, i, start, stop) for (itype i=start, _end=stop; i < _end; ++i)
-#define c_forrange5(itype, i, start, stop, step) \
+#define c_forrange1(stop) c_forrange4(_c_i, size_t, 0, stop)
+#define c_forrange2(i, stop) c_forrange4(i, size_t, 0, stop)
+#define c_forrange3(i, itype, stop) c_forrange4(i, itype, 0, stop)
+#define c_forrange4(i, itype, start, stop) \
+ for (itype i=start, _end=stop; i < _end; ++i)
+#define c_forrange5(i, itype, start, stop, step) \
for (itype i=start, _inc=step, _end=(stop) - (0 < _inc) \
; (i <= _end) == (0 < _inc); i += _inc)