aboutsummaryrefslogtreecommitdiffhomepage
path: root/c/c.h
diff options
context:
space:
mode:
author lemon<lsof@mailbox.org>2025-12-15 22:39:52 +0100
committer lemon<lsof@mailbox.org>2025-12-15 22:39:52 +0100
commit302e24671942051d70707586cf8c605a5815edac (patch)
tree51e25fb6cd7e828c82ce5f17ffc775117121acee /c/c.h
parentc6c0f2ef35175075e91169113cfe856f29b3eb9a (diff)
create distinct interned string type
Interned strings are used pervasively, so it's a good idea to add a layer of type safety to differentiate them from general cstrs and avoid potential bugs from comparing non-interned and interned strings. Not that that's happened so far that I can remember, but it could. I'm 90% sure it's legal to alias `struct {char c;}` pointers with `char` pointers. This specific typedef gives type safety but with a simple one-way `internstr -> const char *` typecast (with `&istr->c`). Converting the other way around is more intentional: a straight up cast `(internstr)cstr` which sticks out as unchecked and probably wrong, or calling the intern(cstr) function, which is the right way.
Diffstat (limited to 'c/c.h')
-rw-r--r--c/c.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/c/c.h b/c/c.h
index a19542b..9000496 100644
--- a/c/c.h
+++ b/c/c.h
@@ -92,9 +92,9 @@ struct decl {
isdef : 1,
isbuiltin : 1;
struct span span;
- const char *name;
+ internstr name;
union {
- const char *sym;
+ internstr sym;
struct { ushort align; int id; };
vlong value;
const struct builtin *builtin;