3 ms·
I just ran strtod through a debugger it at least ends up in strlen.S, so it probably wont improve the runtime complexity . It seems to be best to just assume th
by josefx 6y ago
I just ran strtod through a debugger it at least ends up in strlen.S, so it probably wont improve the runtime complexity . It seems to be best to just assume the worst when it comes to any functions in the C standard library that have to do with string handling and avoid them in favor of literally anything else.
- jchw 6y agoDid you call strtod with a null endptr? If not, I'd be surprised if it actually strlen'd the input rather than a copy of it. Still, I agree, you shouldn't really use the C standard library to do strings.
- bscphil 6y ago> Still, I agree, you shouldn't really use the C standard library to do strings. As someone who's been learning some C, I wonder if you have a recommendation for a guide on how to handle strings properly.
- cormacrelf 6y agoIt probably shouldn’t involve writing your own string functions. They’re so hard to get right, obviously. Last time I wrote C, I copied out the Rust Vec and String API as C headers and didn’t quite nail the implementation, but it was fun. There are at least a few libs like sds that store the length information in various ways, which solves at least this kind of problem. https://github.com/antirez/sds https://github.com/antirez/sds
- jchw 6y agoThere’s plenty of string libraries, although ultimately no answer is perfect. It’s totally OK to use the libc string routines when learning C, but it would be good to keep in mind that it is not necessarily easy to write safe and correct software using it. (Languages with more advanced string types and slicing mechanics are not impacted; C++, Rust, Go, etc. They do have their own issues of course.)