荔园在线
荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀
[回到开始]
[上一篇][下一篇]
发信人: georgehill (终生勤奋便成天才), 信区: Linux
标 题: 转载:GNU 编码标准(Coding Standards)
发信站: BBS 荔园晨风站 (Tue Jan 4 18:20:46 2000), 转信
发信人: finger (肉猫), 信区: Linux
标 题: 转载:GNU 编码标准(Coding Standards)
发信站: BBS 水木清华站 (Mon Jan 3 20:40:48 2000)
原文在
http://gnu.clinux.org/prep/standards.html
看过之后随手记录了一点儿
Linux 命令行参数处理,
getopt();
getopt_long();
getopt_long_only();
在调用过程中多使用高层的接口;
eg. readdir;
signal handling facilities 信号处理:
1. BSD: signal the Best
#include <signal.h>
2. POSIX: sigaction
3. USG: signal
使用临时文件,请检查环境变量TMPDIR
使用由它指定的目录
编码格式:
or, if you want to use ANSI C, format the definition like this:
static char *
concat (char *s1, char *s2)
{
...
}
In ANSI C, if the arguments don't fit nicely on one line, split it
like this:
int
lots_of_args (int an_integer, long a_long, short a_short,
double a_double, float a_float)
...
Try to avoid having two operators of different precedence at the same
level of indentation. For example, don't write this:
mode = (inmode[j] == VOIDmode
|| GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])
? outmode[j] : inmode[j]);
Instead, use extra parentheses so that the indentation shows the
nesting:
mode = ((inmode[j] == VOIDmode
|| (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])))
? outmode[j] : inmode[j]);
Insert extra parentheses so that Emacs will indent the code properly.
For example, the following indentation looks nice if you do it by hand,
v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
+ rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
but Emacs would alter it. Adding a set of parentheses produces something
that looks equally nice, and which Emacs will preserve:
v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
+ rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
Format do-while statements like this:
do
{
a = foo (a);
}
while (a > 0);
清洗的使用C语言的构造:
1.不要省略int类型的声明;
2.-Wall
3.不要在函数内部进行extern声明;
4.在函数中使用另外的形参命名方式;
5.不要在局部变量和参数中映射全局变量;
变量和函数的命名方法:
1.在定义全局变量和函数的时候,不要使用过于简单的命名方法,要通过名字反映它
们的用途;
2.不要过分使用缩写;
3.使用下划线来分割名字中的单词;
4.使用枚举类型来定义constant int,而不要用#define
不同系统间的可移植性:
1.使用Autoconf来进行配置;
2.define the "feature test macro" _GNU_SOURCE when compiling your C
files.
调用系统函数:
1.不要使用sprintf的返回值;
2.vfprintf不是都提供的;
3.main要返回int;
4.不要明确的声明系统函数;
5.如果必须定义系统函数的话,不要指明参数类型;
6.对于处理string的函数需要特别对待;
i18n,国际化:
1.要在每一个程序中使用gettext库;
eg. printf (gettext ("Processing file `%s'..."));
程序的文档化:
发布过程:
Makefile约定:
--
书山有路勤为径;
学海无涯苦作舟!
我是来自大富翁的小美!^_^
※ 来源:·BBS 荔园晨风站 bbs.szu.edu.cn·[FROM: 192.168.1.115]
[回到开始]
[上一篇][下一篇]
荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店