News for hackers. Stuff that matters.
Re:“People who implement new and improved interfaces always ... by unfamiliar on Friday September 11, 2015 @01:12PM (#10204859)
String processing in C is a nightmare. It looks like you basically have to be omniscient to avoid every corner case and potential error.
Re:“People who implement new and improved interfaces always ... by ExpiredLink on Friday September 11, 2015 @02:10PM (#10205249)
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.
Re:“People who implement new and improved interfaces always ... by throwaway000002 on Friday September 11, 2015 @04:00PM (#10205849)
Have 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?
Re:“People who implement new and improved interfaces always ... by WalterBright on Friday September 11, 2015 @04:36PM (#10206037)
The 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

Re:“People who implement new and improved interfaces always ... by joveian on Saturday September 12, 2015 @06:21PM (#10209592)
I 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.

Re:“People who implement new and improved interfaces always ... by mzs on Friday September 11, 2015 @04:27PM (#10205997)
There 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

I've used Ustr before, all of them have pros and cons depending on what you are needing.

Re:“People who implement new and improved interfaces always ... by throwaway000002 on Saturday September 12, 2015 @04:33PM (#10209262)
Thanks 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.

Re:“People who implement new and improved interfaces always ... by vezzy-fnord on Friday September 11, 2015 @04:14PM (#10205918)
Custom 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.
Re:“People who implement new and improved interfaces always ... by ExpiredLink on Friday September 11, 2015 @04:34PM (#10206028)
A string library may mitigate but cannot solve the problem. In C you always need to take allocation/deallocation into consideration.
Re:“People who implement new and improved interfaces always ... by AndyKelley on Friday September 11, 2015 @01:55PM (#10205153)
String processing in computers is difficult. You have to be careful to avoid every corner case and potential error.
Re:“People who implement new and improved interfaces always ... by progmal1 on Friday September 11, 2015 @02:33PM (#10205382)
Add multiple character sets/encodings/conversions and welcome to hell.
Re:“People who implement new and improved interfaces always ... by ExpiredLink on Friday September 11, 2015 @04:36PM (#10206036)
> String processing in computers is difficult.

Not in e.g. Java and many scripting languages.

Re:“People who implement new and improved interfaces always ... by ori_b on Friday September 11, 2015 @10:43PM (#10207048)
Write a function that takes three Unicode strings, concatenates the first two, and returns whether they are equivalent to the third.

If your answer is "use a library", that holds for C too.

Re:“People who implement new and improved interfaces always ... by krylon on Friday September 11, 2015 @04:28PM (#10206004)
Re:“People who implement new and improved interfaces always ... by draw_down on Friday September 11, 2015 @04:51PM (#10206104)
Yes, I agree. Even picking the right function that truncates a string for you, or whatever, seems incredibly fraught. Footguns.