atoi 的由来

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

发表评论

电子邮件地址不会被公开。 必填项已用*标注