News for hackers. Stuff that matters.
Re:C Strings and my slow descent to madness by bluetomcat on Thursday April 06, 2023 @09:46AM (#35468241)
The best way to write C is to treat strings as memory locations with characters and nothing more. Every such memory location has an allocated size, either statically at compile-time (with literals and arrays), or dynamically with malloc and friends. Treat string operations as mere memory operations and don't imagine them to be something else. The str* functions from the standard library are just convenience helpers which are not adding "string" functionality whatsoever.
Re:C Strings and my slow descent to madness by nerdponx on Thursday April 06, 2023 @10:54AM (#35469140)
Maybe you could summarize this by saying that C strings are "strings of bytes", not "strings of characters".
Re:C Strings and my slow descent to madness by lolcatuser on Thursday April 06, 2023 @07:54PM (#35476201)
It's better to say that, in C, characters are bytes. That's why coming at this from the modern perspective of "characters are the things on my screen" is always going to confuse you - C doesn't have bytes, only characters. C programmers (should) understand this the same way Lisp programmers understand that "CAR" and "CDR" refer to "first" and "rest" or Forth programmers understand that "the stack" is the data stack and has no relation to the call stack.
Re:C Strings and my slow descent to madness by nerdponx on Friday April 07, 2023 @11:46AM (#35482896)
So a "char" is a byte, but a "char" is perhaps not a "character", except as a funny coincidence of jargon.