3 ms·
Don't know why you are voted down, string processing is indeed unpleasantly difficult in C. Partly because a built-in string type would conflict with C's simpli
by ExpiredLink 11y ago
Don't know why you are voted down, string processing is indeed unpleasantly difficult in C. Partly because a built-in string type would conflict with C's simplistic compile/link schema.
- throwaway000002 11y agoHave there been any serious attempts at an alternate string library interface for C, perhaps even an total redo of the standard C library with decades of hindsight?
- vezzy-fnord 11y agoCustom string libraries for C are plenty. Pretty much all large C projects accumulate extensive libraries of utility functions, and string processing is a common one to abstract.
- WalterBright 11y agoThe main difficulty with strings in C is caused by arrays decaying to pointers whenever passed to a function. My article about it: http://digitalmars.com/articles/b44.html http://digitalmars.com/articles/b44.html
- joveian 11y agoI just recently discovered that modern C actually has syntax for forcing sized arrays as function arguments. You can do: foo(size_t n, char arr[restrict static n]) The static qualifier here means "no really, I actually want the compiler to complain if the passed array isn't the size indicated". (because C doesn't have enough different meanings for the word "static" :( ). I haven't seen this in the wild yet or checked if gcc and clang actually implement it usefully, but it seems like it could be quite useful.
- mzs 11y agoThere have been /many/ attempts. Here's a link to a comment on the sds from redis post (yet another alternative string library) that links to a nice overview of a number of alternatives: https://news.ycombinator.com/item?id=7191509 https://news.ycombinator.com/item?id=7191509 I've used Ustr before, all of them have pros and cons depending on what you are needing.
- throwaway000002 11y agoThanks mzs for that great reference to an old HN comment. Appreciated! The volume of string libraries only suggests how crucial core library design, often an afterthought, is to programming language design. The language itself encourages idioms, and it's for the core library to harness these idioms into a robust, cohesive, comprehensive toolbox for common tasks.
- deleted 11y ago[deleted]
- ExpiredLink 11y agoA string library may mitigate but cannot solve the problem. In C you always need to take allocation/deallocation into consideration.