summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-01-20 10:00:29 +0100
committerTyge Løvset <[email protected]>2023-01-20 10:00:29 +0100
commit9e6b763fb28c783b8d856442a6929026257bff92 (patch)
tree016867546f86d5260bd0657c8d8df1be3b2c3bea
parentf8accdbcee0b397ad6ba2f2c2c64575a003e71e5 (diff)
downloadSTC-modified-9e6b763fb28c783b8d856442a6929026257bff92.tar.gz
STC-modified-9e6b763fb28c783b8d856442a6929026257bff92.zip
Renamed macro function c_initialize() to c_init().
Minor internal improvements.
-rw-r--r--README.md2
-rw-r--r--include/stc/ccommon.h4
-rw-r--r--include/stc/priv/altnames.h (renamed from include/stc/priv/lowcase.h)4
-rw-r--r--misc/examples/printspan.c41
4 files changed, 27 insertions, 24 deletions
diff --git a/README.md b/README.md
index f184e597..2ba88048 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ STC - Smart Template Containers for C
News: Version 4.1 Beta (Dec 2022)
------------------------------------------------
-- Major change is uppercase macros in ccommon.h. Lowercase macros are [still supported](include/stc/priv/lowcase.h).
+- Major change is uppercase macros in ccommon.h. Lowercase macros are [still supported](include/stc/priv/altnames.h).
- [See detailed changes for version 4](#version-4).
Introduction
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index 09befa56..35bc9335 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -29,7 +29,7 @@
#include <stdbool.h>
#include <string.h>
#include <assert.h>
-#include "priv/lowcase.h"
+#include "priv/altnames.h"
#if SIZE_MAX == UINT32_MAX
#define c_ZU PRIu32
@@ -112,7 +112,7 @@
#define c_no_hash (1<<6)
#define c_no_lookup (c_no_cmp|c_no_eq|c_no_hash)
-#define c_initialize(C, ...) \
+#define c_init(C, ...) \
C##_from_n((C##_raw[])__VA_ARGS__, sizeof((C##_raw[])__VA_ARGS__)/sizeof(C##_raw))
/* Function macros and various others */
diff --git a/include/stc/priv/lowcase.h b/include/stc/priv/altnames.h
index cb6ed991..7f58384c 100644
--- a/include/stc/priv/lowcase.h
+++ b/include/stc/priv/altnames.h
@@ -44,13 +44,13 @@
#define c_sv c_SV
#define c_DROP c_drop
+#define c_DELETE c_delete
+#define c_SWAP c_swap
#define c_FIND_IF c_find_if
#define c_ERASE_IF c_erase_if
#define c_FLT_TAKE c_flt_take
#define c_FLT_SKIP c_flt_skip
#define c_FLT_SKIPWHILE c_flt_skipwhile
#define c_FLT_TAKEWHILE c_flt_takewhile
-#define c_DELETE c_delete
-#define c_SWAP c_swap
#define c_CONTAINER_OF c_container_of
#define c_STATIC_ASSERT c_static_assert
diff --git a/misc/examples/printspan.c b/misc/examples/printspan.c
index 6292cecf..8d0b0321 100644
--- a/misc/examples/printspan.c
+++ b/misc/examples/printspan.c
@@ -12,40 +12,43 @@
#include <stc/cset.h>
#include <stc/cspan.h>
-using_cspan(ispan, int, 1);
+using_cspan(intspan, int, 1);
-void printMe(ispan container) {
- printf("%d\n", (int)cspan_size(&container));
- c_FOREACH (e, ispan, container) printf("%d ", *e.ref);
+void printMe(intspan container) {
+ printf("%d:", (int)cspan_size(&container));
+ c_FOREACH (e, intspan, container) printf(" %d", *e.ref);
puts("");
}
-int main() {
+int main()
+{
c_AUTO (cvec_int, vec)
c_AUTO (cstack_int, stk)
c_AUTO (cdeq_int, deq)
c_AUTO (cset_str, set)
{
- int arr[] = {1, 2, 3, 4, 5};
- ispan sp = cspan_from_array(arr);
- printMe((ispan)cspan_subspan(&sp, 1, 3));
+ printMe( c_init(intspan, {1, 2, 3}) );
- printMe(c_initialize(ispan, {1, 2, 3, 4}));
+ int arr[] = {1, 2, 3, 4, 5, 6};
+ intspan span = cspan_from_array(arr);
+ printMe( (intspan)cspan_subspan(&span, 1, 4) );
- printMe((ispan)cspan_from_array(arr));
+ c_FORLIST (i, int, {1, 2, 3, 4, 5})
+ cvec_int_push(&vec, *i.ref);
+ printMe( (intspan)cspan_from(&vec) );
- c_FORLIST (i, int, {1, 2, 3, 4, 5, 6}) cvec_int_push(&vec, *i.ref);
- printMe((ispan)cspan_from(&vec));
+ printMe( span );
- stk = c_initialize(cstack_int, {1, 2, 3, 4, 5, 6, 7});
- printMe((ispan)cspan_from(&stk));
+ stk = c_init(cstack_int, {1, 2, 3, 4, 5, 6, 7});
+ printMe( (intspan)cspan_from(&stk) );
- deq = c_initialize(cdeq_int, {1, 2, 3, 4, 5, 6, 7, 8});
- printMe((ispan)cspan_from(&deq));
+ deq = c_init(cdeq_int, {1, 2, 3, 4, 5, 6, 7, 8});
+ printMe( (intspan)cspan_from(&deq) );
- set = c_initialize(cset_str, {"1", "2", "3", "4", "5", "6", "7", "8", "9"});
- printf("%d\n", (int)cset_str_size(&set));
- c_FOREACH (e, cset_str, set) printf("%s ", cstr_str(e.ref));
+ set = c_init(cset_str, {"1", "2", "3", "4", "5", "6", "7", "8", "9"});
+ printf("%d:", (int)cset_str_size(&set));
+ c_FOREACH (e, cset_str, set)
+ printf(" %s", cstr_str(e.ref));
puts("");
}
}