Google C++ 编程规范总结

时间:2014-10-06 19:05:10   收藏:0   阅读:178

一、头文件

  1. #define 的保护

    项目 foo 中的头文件 foo/src/bar/baz.h 按如下方式保护:

    #ifndef FOO_BAR_BAZ_H_
    #define FOO_BAR_BAZ_H_
    ...
    #endif //FOO_BAR_BAZ_H_
    #ifdef WINDOWS #define MYTYPE long #else #define MYTYPE float #endif
    #ifndef WINDOWS #define MYTYPE long #else #define MYTYPE float #endif
    用于代码调试:
    #ifdef DEBUG 
    print ("device_open(%p) ", file); 
    #endif
    在它前面必须有:
    #define DEBUG
    起到一个开关作用。
  2. 内联函数

    不要内联超过 10 行的函数。

  3. 函数参数顺序

    定义函数时,输入参数在前,输出参数在后。

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!