前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >atoi 的由来

atoi 的由来

作者头像
柳公子
发布2020-07-30 14:49:36
1.1K0
发布2020-07-30 14:49:36
举报
文章被收录于专栏:PhpZendoPhpZendo

go 语言 strconv 包中有两个方法 Atoi 和 Itoa;功能是将「字符串转成整型」和「将整型转换成字符串」,但是并不知道为什么这么命名函数名

SO 上有个提问解释了它们的由来:https://stackoverflow.com/questions/2909768/where-did-the-name-atoi-come-from

以下是问题

In the C language where did they come up with the name atoi for converting a string to an integer? The only thing I can think of is Array To Integer for an acronym but that doesn't really make sense.

C 语言 atoi 方法将 string 转化成 integer 的由来是什么?我猜测它的命令类似 Array 转成 Integer 的首字母缩写,但这说服力并不强。

回答:

It means Ascii to Integer. Likewise, you can have atol for Ascii to Long, atof for Ascii to Float, etc. 它的意思是 Ascii 转成 Integer。类似的,atol 表示 Ascii 转成 Long, atof 为 Ascii转成 Float 等等。

A Google search for 'atoi "ascii to integer"' confirms this on several pages. Google 搜索 'atoi "ascii to integer"' 会有相关解释。

I'm having trouble finding any official source on it... but in this listing of man pages from Third Edition Unix (1973) collected by Dennis Ritchie himself, it does contain the line:

但我并没有找到可靠的官方详细来源... 但是这个由 Dennis Ritchie 收集的第三版 Unix(1973) 手册中,确实有这样一行代码:

atoi(III): convert ASCII to integer

In fact, even the first edition Unix (ca 1971) man pages list atoi as meaning Ascii to Integer.

事实上,在第一版中,既有 atoi 表示 Ascii 转成 Integer 的解释。

So even if there isn't any documentation more official than man pages indicating that atoi means Ascii to Integer (I suspect there is and I just haven't been able to locate it), it's been Ascii to Integer by convention at least since 1971.

因此,即使没有比手册更官方的文档表明 atoi 表示 Ascii 转成 Integer(我怀疑有,我只是无法找到它),至少从 1971 年开始,按照约定它就是代表 Ascii 转 Integer。

文档在这里: https://minnie.tuhs.org/cgi-bin/utree.pl?file=V1/man/man3/atoi.3

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020年7月29日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 以下是问题
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档