atol() v/s. strtol()

前端 未结 7 1679
伪装坚强ぢ
伪装坚强ぢ 2020-11-30 19:13

What is the difference between atol() & strtol()?

According to their man pages, they seem to have the same effect as well as matching arguments:

         


        
相关标签:
7条回答
  • 2020-11-30 20:12

    atol functionality is a subset of strtol functionality, except that atol provides you with no usable error handling capabilities. The most prominent problem with ato... functions is that they lead to undefined behavior in case of overflow. Note: this is not just a lack of informative feedback in case of an error, this is undefined behavior, i.e. generally an unrecoverable failure.

    This means that atol function (as well as all other ato.. functions) is pretty much useless for any serious practical purposes. It was a design mistake and its place is on the junkyard of C history. You should use functions from strto... group to perform the conversions. They were introduced, among other things, to correct the problems inherent in functions of ato... group.

    0 讨论(0)
提交回复
热议问题