News for hackers. Stuff that matters.
Re:Why is strlen so complex in C? by m463 on Monday August 26, 2019 @07:48PM (#20804867)
Optimization hacks aside, I swoon at the simple (and verified) seL4 implementation (note strNlen):

  word_t strnlen(const char *s, word_t maxlen)
  {
      word_t len;
      for (len = 0; len < maxlen && s[len]; len++);
      return len;
  }

http://sel4.systems/

https://github.com/seL4/seL4 (from file src/string.c)

Re:Why is strlen so complex in C? by ridiculous_fish on Monday August 26, 2019 @08:49PM (#20805238)
The trailing semicolon on that for loop is quite load-bearing. I would have some code review feedback.
Re:Why is strlen so complex in C? by anticensor on Sunday September 08, 2019 @03:34PM (#20912841)
It can be replaced by continue; in this specific case.
Re:Why is strlen so complex in C? by goalieca on Monday August 26, 2019 @09:59PM (#20805677)
Looks very simple to me. I love it.
Re:Why is strlen so complex in C? by rurban on Tuesday August 27, 2019 @03:17AM (#20807014)
Nope, for sure not.

A good implementation would stick to the standard (size_t nor word_t), and would inc the pointer, not the counter. Formatting would be better (the final ; ouch).

This is junior stuff.

Re:Why is strlen so complex in C? by m463 on Tuesday August 27, 2019 @08:36PM (#20815789)
Maybe verification tools choke on pointer incrementing?

Having worked on a variety of code bases and coding styles, I think if there are coding rules and they are consistent across all the source files, it becomes easy to read even with wierdnesses. I hated perl with @_ and $_, but after working with it enough they became known quantities.

And you can probably read all the lines of code in your lifetime, since the whole microkernel is ~30k lines of code.