From af74e5f44af8f03ec3b0b2ffd3fd577210707e49 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Sun, 22 Jan 2023 16:22:51 +0100 Subject: Added cspan_init() for static initializing and a minor fix. Added cregex replace tests. --- include/stc/cspan.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/stc/cspan.h b/include/stc/cspan.h index 96439c64..1e12781e 100644 --- a/include/stc/cspan.h +++ b/include/stc/cspan.h @@ -61,7 +61,7 @@ int demo2() { #include "ccommon.h" #define using_cspan(Self, T, RANK) \ - typedef T Self##_value, Self##_raw; \ + typedef T Self##_value; typedef T Self##_raw; \ typedef struct { Self##_value *ref, *end; } Self##_iter; \ typedef struct { Self##_value *data; uint32_t dim[RANK]; } Self; \ \ @@ -90,6 +90,10 @@ int demo2() { #define cspan_make(array, ...) \ {.data=array, .dim={__VA_ARGS__}} +/* For static initialization use , cspan_init(). c_init() only works for non-static. */ +#define cspan_init(SpanType, ...) \ + {.data=(SpanType##_value[])__VA_ARGS__, .dim={sizeof((SpanType##_value[])__VA_ARGS__)/sizeof(SpanType##_value)}} + /* create a cspan from a cvec, cstack, cdeq, cqueue, or cpque (heap) */ #define cspan_from(container) \ {.data=(container)->data, .dim={(uint32_t)(container)->_len}} -- cgit v1.2.3