-
Make use of return values to communicate information and to make error trapping easy for the calling program.
用好返回值,使得错误处理简单一些。
-
Do not exit from functions. Instead, return an error value to allow the calling program flexibility in handling the error.
不要在函数中使用exit,明确的返回错误码,让caller来决定到底怎么办。
-
Make functions general but usable. (Sometimes these are conflicting goals.)
既通用,又好用。
-
Do not make unnecessary assumptions about sizes of buffers. (This is often hard to implement.)
不要对输入buffer的长度做不必要的架设。
-
When it is necessary to use limits, use standard system-defined limits rather than arbitrary constants.
尽可能使用系统的limits
-
Do not reinvent the wheel—use standard library functions when possible.
尽可能使用标准库
-
Do not modify input parameter values unless it makes sense to do so.
尽可能不要修改输入参数
-
Do not use static variables or dynamic memory allocation if automatic allocation will do just as well.
如果自动变量就能搞定,不要用static变量。
-
Analyze all the calls to the malloc family to make sure the program frees the memory that was allocated.
看好malloc,避免泄露。
-
Consider whether a function is ever called recursively or from a signal handler or from a thread. Functions with variables of static storage class may not behave in the desired way. (The error number can cause a big problem here.)
在函数被递归调用,或反复调用的情况下,static变量的存在,将会导致不可预期的行为。
-
Analyze the consequences of interruptions by signals.
要把signal的中断考虑进来。
-
Carefully consider how the entire program terminates.
小心处理程序的退出。