strtok函数设计
strtok() 函数使用静态变量。
因此它是不可重入的。并且不能用于解析多个字符串。
我想知道的是为什么strtok()要这样设计? strtok_r() 应该是 strtok()。
这个函数将来会保留在标准库中吗?
strtok() function uses static variable.
Thus it's not re-entrant. and cannot be used to parse multiple strings.
What I want to know is why strtok() is designed this way?
strtok_r() should have been strtok().
Will this function going to stay in standard library in future?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
功能不会改变。向后兼容性对于标准来说是一件大事。
为什么函数不可重入?嗯,在 70 年代设计它时我并不在场,但我认为它所编写的用例不需要可重入性。然后它的使用扩展,因为它是有用的,并且保持兼容性比可重入的增加的灵活性更可取。最后,委员会规范了现有的做法,而不是在已有解决方案的情况下设计新的解决方案。
The function won't change. Backward compatibility is a big thing for standards.
Why is the function not reentrant? Well, I wasn't there in the 70s when it was designed, but I assume that reentrency wasn't needed for the use cases it was written. Then its use spread of as it was useful and keeping compatibility was more a desirable than the added flexibility of reentrency. And finally the committee normalized the existing practice and instead of designing a new solution when there was already existing one.