📄 00000012.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: finger (肉猫), 信区: Linux <BR>标 题: GNU 编码标准(Coding Standards) <BR>发信站: BBS 水木清华站 (Mon Jan 3 20:40:48 2000) <BR> <BR>原文在 <BR> <BR> <A HREF="http://gnu.clinux.org/prep/standards.html">http://gnu.clinux.org/prep/standards.html</A> <BR>看过之后随手记录了一点儿 <BR> <BR>Linux 命令行参数处理, <BR>getopt(); <BR>getopt_long(); <BR>getopt_long_only(); <BR> <BR>在调用过程中多使用高层的接口; <BR>eg. readdir; <BR> <BR>signal handling facilities 信号处理: <BR>1. BSD: signal the Best <BR> #include <signal.h> <BR>2. POSIX: sigaction <BR>3. USG: signal <BR> <BR>使用临时文件,请检查环境变量TMPDIR <BR>使用由它指定的目录 <BR> <BR>编码格式: <BR>or, if you want to use ANSI C, format the definition like this: <BR> <BR>static char * <BR>concat (char *s1, char *s2) <BR>{ <BR> ... <BR>} <BR> <BR>In ANSI C, if the arguments don't fit nicely on one line, split it <BR>like this: <BR> <BR>int <BR>lots_of_args (int an_integer, long a_long, short a_short, <BR> double a_double, float a_float) <BR>... <BR> <BR>Try to avoid having two operators of different precedence at the same <BR>level of indentation. For example, don't write this: <BR> <BR>mode = (inmode[j] == VOIDmode <BR> || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j]) <BR> ? outmode[j] : inmode[j]); <BR> <BR>Instead, use extra parentheses so that the indentation shows the <BR>nesting: <BR> <BR>mode = ((inmode[j] == VOIDmode <BR> || (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j]))) <BR> ? outmode[j] : inmode[j]); <BR> <BR>Insert extra parentheses so that Emacs will indent the code properly. <BR>For example, the following indentation looks nice if you do it by hand, <BR> <BR> <BR>v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000 <BR> + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000; <BR> <BR>but Emacs would alter it. Adding a set of parentheses produces something <BR> that looks equally nice, and which Emacs will preserve: <BR> <BR>v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000 <BR> + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000); <BR> <BR>Format do-while statements like this: <BR> <BR>do <BR> { <BR> a = foo (a); <BR> } <BR>while (a > 0); <BR> <BR>清洗的使用C语言的构造: <BR>1.不要省略int类型的声明; <BR>2.-Wall <BR>3.不要在函数内部进行extern声明; <BR>4.在函数中使用另外的形参命名方式; <BR>5.不要在局部变量和参数中映射全局变量; <BR> <BR>变量和函数的命名方法: <BR>1.在定义全局变量和函数的时候,不要使用过于简单的命名方法,要通过名字反映它 <BR>们的用途; <BR>2.不要过分使用缩写; <BR> <BR>3.使用下划线来分割名字中的单词; <BR>4.使用枚举类型来定义constant int,而不要用#define <BR> <BR>不同系统间的可移植性: <BR>1.使用Autoconf来进行配置; <BR>2.define the "feature test macro" _GNU_SOURCE when compiling your C <BR>files. <BR> <BR>调用系统函数: <BR>1.不要使用sprintf的返回值; <BR>2.vfprintf不是都提供的; <BR>3.main要返回int; <BR>4.不要明确的声明系统函数; <BR>5.如果必须定义系统函数的话,不要指明参数类型; <BR>6.对于处理string的函数需要特别对待; <BR> <BR>i18n,国际化: <BR>1.要在每一个程序中使用gettext库; <BR> eg. printf (gettext ("Processing file `%s'...")); <BR> <BR>程序的文档化: <BR> <BR>发布过程: <BR> <BR>Makefile约定: <BR> <BR> <BR> <BR> <BR>-- <BR> <BR><---<<<< <BR>[u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P <BR>[u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P <BR>[u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P <BR>[u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P [u[1P <BR> <BR>※ 来源:·BBS 水木清华站 smth.org·[FROM: finger.lib.tsin] <BR><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -