我读过它atoi()
已被弃用,它相当于:
(int)strtol(token_start, (char **)NULL, 10);
Run Code Online (Sandbox Code Playgroud)
这是否意味着我应该使用上述代替atoi(chr)
或仅仅是说它们是等价的?
Lun*_*din 13
atoi
不推荐使用,您的来源不正确.当前的C标准ISO 9899:2011中没有任何内容表明这一点(例如参见第6.11章未来语言方向),也没有早期标准中的任何内容.
根据C标准,atoi相当于strtol如下,C11 7.22.1.2:
atoi,atol和atoll函数分别将nptr指向的字符串的初始部分转换为int,long int和long long int表示.
除了出错的行为,它们相当于
atoi: (int)strtol(nptr, (char **)NULL, 10)
atol: strtol(nptr, (char **)NULL, 10)
atoll: strtoll(nptr, (char **)NULL, 10)
strtol是首选,因为atoi在出错时调用未定义的行为.请参见7.22.1"如果无法表示结果的值,则行为未定义."
Joh*_*ker 10
它确实在Apple的Mac OS X手册页上为atoi(3)(以及BSD手册页)中atoi
已经弃用了.
atoi()函数已被strtol()弃用,不应在新代码中使用.
我会strtol()
因为这个原因使用等效物,但我怀疑你不得不担心atoi()
被移除.
来自http://www.codecogs.com/library/computing/c/stdlib.h/atoi.php
实施说明
* The atoi function is not thread-safe and also not async-cancel safe.
* The atoi function has been deprecated by strtol and should not be used in new code.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16512 次 |
最近记录: |