summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2026-01-02 19:54:50 -0500
committerWormHeamer2026-01-02 19:54:50 -0500
commit798afa8d742e39223533865a50f82ad6be10df97 (patch)
treeb87d27fe71106e458181213b84e18efcdf643b00
parentecdb6e57fcf3b0d4145eac498073bb181f792b6e (diff)
add a reminder comment about strings' immutability
-rw-r--r--str.h9
1 files changed, 8 insertions, 1 deletions
diff --git a/str.h b/str.h
index 1969d6b..33decac 100644
--- a/str.h
+++ b/str.h
@@ -1,11 +1,16 @@
#ifndef STR_H
#define STR_H
-#include <string.h>
#include <stddef.h>
#include "arena.h"
+/* non-const *s for convenience's sake, but strings should
+ * be treated as immutable unless absolutely certain there
+ * are no dangling references to substrings concatenated
+ * into it (because str_cat() is sometimes in-place).
+ */
+
typedef struct {
char *s;
ptrdiff_t n;
@@ -43,6 +48,8 @@ Str str_replace_end(Str s, Str a, Str b, Arena *m);
#ifdef STR_IMPL
+#include <string.h>
+
/* conversions */
Str str_from_cstr(const char *s) {