Conversation

aki-nyan //nullptr::live

I know this would break so much ABI and other stuff, but I really wish there was a compiler flag to switch from null-terminated strings to length-prefixed strings in C.

Null-terminated strings are a mistake and we will never recover from it, it's too late.

6
2
0
@lethalbit so like string literals would generate some `struct { size_t len; char str[]; };`?

Yeah, I want that too. Just an option, like some kind of string literal prefix like the L for wchar_t strings, would change the situation for good so much.
0
0
0
@lethalbit Well it could just be a typedef struct in POSIX or something.
0
0
0

@lethalbit maybe strings should end in '$' :P

But yes, i agree…

0
0
0
@lethalbit i mean that's kind of impossible to be a switch, not just bc of abi but bc sometimes we just can't know the length without code to do so

but it's not too late. not only a lot of projects use their own length prefixes strings internally, but there's proposals to adding such type to libc going forward

(on syscalls tho, i do think it's too late, those won't change, but we can always add wrappers on top of them)
0
0
0