4 ms·
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
by burnt-resistor 5mo 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.
- coolThingsFirst 5mo agoIt 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.