Re:Git's list of banned C functions
by yxhuvud on Thursday March 04, 2021 @04:31PM
(#26348650)
No, if you want sensible string handling, the sane choice is usually to choose to use a language that is not C. Not always, but definitely usually.
[ Parent
| on HN ]
Re:Git's list of banned C functions
by IgorPartola on Thursday March 04, 2021 @04:39PM
(#26348763)
It’s not hard to have strings like you do in other languages in C. It is hard when you treat char foo[] as if it was a string object like you have in JavaScript or Java or Python. C strings are just chunks of memory terminated by \0. They can still be mildly useful that way but if you actually want to do string operations you need to use a library designed for the problem (variable length, storing length with the object, Unicode support, etc.). Problem is that most people don’t start with such a library so they end up doing the hard work themselves in an ad hoc manner.
You can’t fuck up String(“Hello “) + String(“world”) but you can definitely fuck up strcat(buf, “Hello “); strcat(buf, “world”);.