Re: atoi return



Richard Heathfield wrote:
CBFalconer said:
Bill Cunningham wrote:
"Keith Thompson" <kst-u@xxxxxxx> wrote in message

... snip ...

Even worse, if atoi() is given a string that represents a number
that's too big to hold in an int, it invokes undefined behavior.
For example, there's no telling what atoi("99999999999999999999")
will do; it could crash your program or worse.

I see. Must be a left over dinosaur like gets().

No. gets() is just unsafe regardless. atoi() can be used safely,
but why bother when you have strtol available.

In other words, it's a left over dinosaur. And so is gets().
Therefore, it's a left over dinosaur like gets(). Which is what he
said.

Not so. gets should never appear in any code. atoi can. One
objective of the C standard is to preserve the viability of old
code.

I can also see various other differences between gets and atoi. So
the above comment is simply a waste of time.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
.



Relevant Pages

  • Re: atoi return
    ... that's too big to hold in an int, ... atoi() can be used safely, ... it's a left over dinosaur. ... Google users: ...
    (comp.lang.c)
  • Re: atoi return
    ... that's too big to hold in an int, ... atoi() can be used safely, ... it's a left over dinosaur. ... is intended to convert a string value into an int value. ...
    (comp.lang.c)
  • Re: atoi return
    ... snip ... ... that's too big to hold in an int, it invokes undefined behavior. ... it's a left over dinosaur. ...
    (comp.lang.c)
  • Re: Writing a program to sort numbers - HELP!
    ... You may not have a choice but strtol is preferred to atoi and fgets is ... Then we using a sort function to sort the ... >int main ... probably meant *u and *v to dereference the pointers you received from ...
    (comp.lang.c.moderated)
  • Re: Check all errors in code?
    ... The atoi function converts the initial portion of the string ... pointed to by nptr to int representation. ... The atoi function returns the converted value. ... The strtol function returns the converted value, ...
    (comp.lang.c)