3 ms·
My layman understanding is that it's the other way around, C doesn't have a string type. Since C doesn't have a string type, "quoted strings" are actually char
by xnorswap 2y ago
My layman understanding is that it's the other way around, C doesn't have a string type.
Since C doesn't have a string type, "quoted strings" are actually char[] but with '\0' as an extra last character.
People have therefore made warnings happen when defining a char[] which silently truncates the '\0', because that's a common source of bugs.
They've then had to develop a way of easily disabling that warning from being generated, because it's also common enough to want to avoid the warning.
All of this seems insane coming from a modern language.
But look at the complete disaster that was the Python 2 -> 3 migration, a large motivator for which was "fixing" strings from a non-unicode to unicode compatible type. A decade or more of lost productivity as people struggled to migrate.
There's no way to actually fix C. Just keep recommending that people don't use it.
- Philpax 2y agoYep, agreed on all accounts; I'm an advocate for Rust for Linux for these reasons, among others. My thinking was that the Linux kernel already uses a custom dialect of C with specific features that benefit their workflow; I'm surprised that one of those features wasn't a char[] charset = b"abcdefghijklmnopqrstuvwxyz"; that would allow for intent to be signalled to the compiler.
- surajrmal 2y agoRust for Linux still uses null terminated strings for comparability.