tags:

views:

262

answers:

1

I'm a C noob and I just found out that atoi is deprecated in favor of strtol etc.

Where can I find a list of deprecated C functions ?

+1  A: 

There's a difference between unsafe and deprecated. atoi() is unsafe, however gcc is not going to tell you to stop using it because its dangerous. Using gets() produces a different result :) YCMV (your compiler may vary).

In general, if a function can fail and no error checking is possible, don't use it. If a function lets you write to a region of memory with out being able to pass a size limit, don't use it.

The latter is easier to determine just by the function prototype. However, if you are somewhat conscious of what you are doing, you'll quickly realize that you have no way of knowing if what you got from atoi() was really the string representation of the result that a user just entered on the command line.

This rationale is not at all exclusive to the standard C library. You will encounter lots and lots of library code, some of it good. No list can replace learned, defensive coding habits.

Tim Post
gcc is probably assuming you're dealing with a forgiving implementation of the C library. Conceptually, `atoi` and `gets` are equally bad - both result in **undefined behavior** unless you have strict control over the inputs they will receive.
R..