Hacker News new | ask | show | jobs
by burnt-resistor 16 days ago
No, it's not bizarre, it's standardized on what is and isn't UB based on history, and usually for performance.

NUL-terminated strings don't know their lengths and so, without an "n" variant function and running strlen() ahead-of-time, must iterate the entire thing. Pascal format strings (supported up to 255 byte lengths in the classic form) could find length as an O(1) operation because there was no terminator necessarily.

1 comments

It is bizarre. C is bizarre, there is no string type and there should've been a string type. scanf is an invitation for buffer overflow attacks. I know how poorly designed languages look like and C despite its strengths is still a poorly designed language.