Chinaunix首页 | 论坛 | 博客
  • 博客访问: 979812
  • 博文数量: 184
  • 博客积分: 10030
  • 博客等级: 上将
  • 技术积分: 1532
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-27 18:32
文章分类

全部博文(184)

文章存档

2009年(1)

2008年(63)

2007年(39)

2006年(79)

2005年(2)

我的朋友

分类: C/C++

2008-07-10 11:15:47

Most library functions provide good models for implementing functions. Here are guidelines to follow.

  1. Make use of return values to communicate information and to make error trapping easy for the calling program.

  2. Do not exit from functions. Instead, return an error value to allow the calling program flexibility in handling the error.

  3. Make functions general but usable. (Sometimes these are conflicting goals.)

  4. Do not make unnecessary assumptions about sizes of buffers. (This is often hard to implement.)

  5. When it is necessary to use limits, use standard system-defined limits rather than arbitrary constants.

  6. Do not reinvent the wheel—use standard library functions when possible.

  7. Do not modify input parameter values unless it makes sense to do so.

  8. Do not use static variables or dynamic memory allocation if automatic allocation will do just as well.

  9. Analyze all the calls to the malloc family to make sure the program frees the memory that was allocated.

  10. 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.)

  11. Analyze the consequences of interruptions by signals.

  12. Carefully consider how the entire program terminates.



from Unix_Systems_Programming_Communication,_Concurrency,_And_Threads
阅读(1454) | 评论(0) | 转发(0) |
0

上一篇:fstab with UUID

下一篇:C语言中static 变量

给主人留下些什么吧!~~