News for hackers. Stuff that matters.
Re:Why is strlen so complex in C? by kelnos on Wednesday September 04, 2019 @12:04AM (#20873901)
I agree with the answerer that the code is bad. If anyone wrote that anywhere in any code base where I have review responsibility, I would never +1 that.

For deep in the bowels of a compiler or libc, where developers might think it's useful to optimize code that has to be run in a huge variety of impossible-to-predict types of workloads, I'm more sympathetic, but it's objectively not good code. It might be useful and necessary in this very very narrow context, but it's far too clever to be good.

The answerer may have been a bit heavy-handed in knocking it down, but I think it was entirely appropriate when helping to educate someone who is new to C.

I agree that the other answer you link to is probably better, with the caveat that I'm disappointed that there's no warning against writing code like that in the general case. The sentence that starts with "They make assumptions..." is IMO not strong enough to point out that the strlen() code referenced relies on implementation-defined behavior and is not even remotely portable C.

Re:Why is strlen so complex in C? by saagarjha on Thursday September 05, 2019 @12:56PM (#20888576)
FWIW, here's a better answer that was written later: https://stackoverflow.com/a/57676035/5230900.