与atoi是一个标准功能。但itoa不是。为什么? [英] atoi is a standard function. But itoa is not. Why?

查看:640
本文介绍了与atoi是一个标准功能。但itoa不是。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这种区别?我登陆了可怕的问题,假设 itoa 将在文件stdlib.h ,最后用一个连接结束了 itoa 定制版采用了不同的原型,并因此产生一些疯狂的错误。

Why this distinction? I've landed up with terrible problems, assuming itoa to be in stdlib.h and finally ending up with linking a custom version of itoa with a different prototype and thus producing some crazy errors.

那么,为什么不是 itoa 不是一个标准的功能?它出什么问题了?以及为什么是朝其孪生兄弟的标准偏的atoi

So, why isn't itoa not a standard function? What's wrong with it? And why is the standard partial towards its twin brother atoi?

推荐答案

没有 itoa 曾经被标准化,以便将它添加到标准的,你需要一个令人信服的理由和良好的界面进行添加。

No itoa has ever been standardised so to add it to the standard you would need a compelling reason and a good interface to add it.

大多数 itoa 我所看到的接口既可以使用静态缓冲区有重入和寿命问题,分配,调用者需要释放或要求一个动态缓冲区用户提供一个缓冲区,使得界面丝毫不比的sprintf

Most itoa interfaces that I have seen either use a static buffer which has re-entrancy and lifetime issues, allocate a dynamic buffer that the caller needs to free or require the user to supply a buffer which makes the interface no better than sprintf.

这篇关于与atoi是一个标准功能。但itoa不是。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆