3 ms·
It is, in fact, a good question. The C standard library uses NUL-terminated strings, as it did since the design. And the language allows that anything in double
by Aissen 4y ago
It is, in fact, a good question. The C standard library uses NUL-terminated strings, as it did since the design. And the language allows that anything in double quotes will be a NUL-terminated string.
But nothing stops you to store strings another way. There is nothing magic in C for this. Just use whatever layout you like.
You "just" need to re-implement any function manipulating strings in all of the C standard library. You can probably re-use the printf family with GCC using a non-standard approach:
https://www.gnu.org/software/libc/manual/html_node/Customizing-Printf.html https://www.gnu.org/software/libc/manual/html_node/Customizi...
And you need to write conversion of any library/program/kernel that expects NUL-terminated strings.
And there are libraries that do that, like https://github.com/websnarf/bstrlib https://github.com/websnarf/bstrlib (Doc and rationale:
https://raw.githubusercontent.com/websnarf/bstrlib/master/bstrlib.txt https://raw.githubusercontent.com/websnarf/bstrlib/master/bs... ). I've never seen them used in the wild though.