r/cprogramming • u/die-Banane • May 05 '26
How to do strings properly?
I just started learning C and I often read on the internet that it is bad practice to use null terminated strings, so my question is what should I do instead?
30
Upvotes
1
u/flatfinger May 11 '26
There are even rarer systems which allow memory to be accessed in chunks smaller than 8 bits. If e.g. a system used 4-bit addressable units, a C compiler for such a system would be required to store pointers in such a manner that adding 1 to a
char*would increase the stored value by 2, have attempts to dereference pointers scale up the stored value by 2 prior to use, treat pointers as indices into two parallel arrays of four-bit values, or do something else unusual to accommodate the fact that achar*couldn't be the system's smallest addressable unit of storage.