summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-01-03 13:18:44 +0100
committerTyge Løvset <[email protected]>2021-01-03 13:18:44 +0100
commit8d1f5cfac2515738e41cfc8f9e7b96d8c264c349 (patch)
treed7d33f55a372bb9f6b8c9888f283579b4e607d7c
parente4c1dadb85e08d88fbc706e49a5d2b18b39fe0ed (diff)
downloadSTC-modified-8d1f5cfac2515738e41cfc8f9e7b96d8c264c349.tar.gz
STC-modified-8d1f5cfac2515738e41cfc8f9e7b96d8c264c349.zip
Added macro: c_defcnt(): define container and push items onto it.
-rw-r--r--examples/words.c7
-rw-r--r--stc/ccommon.h3
2 files changed, 6 insertions, 4 deletions
diff --git a/examples/words.c b/examples/words.c
index 7e80c452..c8e17deb 100644
--- a/examples/words.c
+++ b/examples/words.c
@@ -11,18 +11,17 @@ using_cmap_strkey(si, int);
int main1()
{
- clist_str lwords = clist_inits;
- c_push_items(&lwords, clist_str, {
+ c_defcnt (clist_str, lwords, {
"this", "sentence", "is", "not", "a", "sentence",
"this", "sentence", "is", "a", "hoax"
});
+
clist_str_push_back(&lwords, cstr_from_fmt("%f", 123897.0 / 23.0));
c_foreach (w, clist_str, lwords)
printf("%s\n", w.ref->str);
puts("");
- cvec_str words = cvec_inits;
- c_push_items(&words, cvec_str, {
+ c_defcnt (cvec_str, words, {
"this", "sentence", "is", "not", "a", "sentence",
"this", "sentence", "is", "a", "hoax"
});
diff --git a/stc/ccommon.h b/stc/ccommon.h
index 797180ce..d595c0eb 100644
--- a/stc/ccommon.h
+++ b/stc/ccommon.h
@@ -120,6 +120,9 @@
ctype##_push_n(self, __arr, sizeof __arr/sizeof *__arr); \
} while (0)
+#define c_defcnt(ctype, cnt, ...) \
+ ctype cnt = ctype##_init(); c_push_items(&cnt, ctype, __VA_ARGS__)
+
#define c_del(ctype, ...) do { \
ctype##_t* __arr[] = {__VA_ARGS__}; \
for (size_t __i=0; __i<sizeof __arr/sizeof *__arr; ++__i) \