From b7f11d024b9a4dfd616c70891a7c34631eeba975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=89=E6=96=87=E6=9D=B0?= Date: Tue, 1 Mar 2016 15:37:33 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E8=A1=A5=E5=85=85:C=E8=AF=AD=E8=A8=80?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 52 ------------------------------------------ 补充:C语言代码规范.md | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 52 deletions(-) create mode 100644 补充:C语言代码规范.md diff --git a/README.md b/README.md index 6d1a3a4..d25585f 100644 --- a/README.md +++ b/README.md @@ -217,58 +217,6 @@ http://ac.jobdu.com/index.php 九度OJ -## 补充:C语言代码规范 - -这里面的算法代码均使用C语言完成,养成良好的代码规范习惯,不但可以写出优质的代码,也可以更快的阅读其他优秀开源代码。代码规范主要有: - -### 符号命名 - -**局部变量** 尽量短,能表达清楚意思即可,能简写就简写,比如"err" 表示 "error"; "fd" 表示文件描述符 ,循环变量可以使用i,j,k ;结构体成员变量不需要"m_"前缀;全局变量"g_"开头 - -**常量名** 全大写,单词之间"_"分割,如 "MAX_NUMBER_OF_SLAB_CLASSES" ; - -**宏定义** 对于options 宏定义,适当使用前缀 ,比如: -``` -/* Client classes for client limits, currently used only for - * the max-client-output-buffer limit implementation. */ -#define CLIENT_TYPE_NORMAL 0 /* Normal req-reply clients + MONITORs */ -#define CLIENT_TYPE_SLAVE 1 /* Slaves. */ -#define CLIENT_TYPE_PUBSUB 2 /* Clients subscribed to PubSub channels. */ -#define CLIENT_TYPE_MASTER 3 /* Master. */ -#define CLIENT_TYPE_OBUF_COUNT 3 -``` - -**枚举** 使用前缀: -``` -enum conn_states { - conn_listening, /**< the socket which listens for connections */ - conn_new_cmd, /**< Prepare connection for next command */ - conn_waiting, /**< waiting for a readable socket */ - conn_read, /**< reading in a command line */ - conn_parse_cmd, /**< try to parse a command from the input buffer */ - conn_write, /**< writing out a simple response */ - conn_nread, /**< reading in a fixed number of bytes */ - conn_swallow, /**< swallowing unnecessary bytes w/o storing */ - conn_closing, /**< closing this connection */ - conn_mwrite, /**< writing out many items sequentially */ - conn_closed, /**< connection is closed */ - conn_max_state /**< Max state value (used for assertion) */ -}; -``` - -**函数命名** 全小写,单词之间"_"分割。如"split_cmdline_strerror()" - - -### 注释 - -所有注释使用 "/* 这里是注释 */ " - - -### 其他 - -合理使用static,const 等关键字,能提升程序的安全性,也能避免函数命名冲突 -合理使用数据类型:rel_time_t,uint8_t,uint32_t,uint64_t,size_t,off_t - ## 联系 diff --git a/补充:C语言代码规范.md b/补充:C语言代码规范.md new file mode 100644 index 0000000..e3b92c5 --- /dev/null +++ b/补充:C语言代码规范.md @@ -0,0 +1,53 @@ + + +## 补充:C语言代码规范 + +这里面的算法代码均使用C语言完成,养成良好的代码规范习惯,不但可以写出优质的代码,也可以更快的阅读其他优秀开源代码。代码规范主要有: + +### 符号命名 + +**局部变量** 尽量短,能表达清楚意思即可,能简写就简写,比如"err" 表示 "error"; "fd" 表示文件描述符 ,循环变量可以使用i,j,k ;结构体成员变量不需要"m_"前缀;全局变量"g_"开头 + +**常量名** 全大写,单词之间"_"分割,如 "MAX_NUMBER_OF_SLAB_CLASSES" ; + +**宏定义** 对于options 宏定义,适当使用前缀 ,比如: +``` +/* Client classes for client limits, currently used only for + * the max-client-output-buffer limit implementation. */ +#define CLIENT_TYPE_NORMAL 0 /* Normal req-reply clients + MONITORs */ +#define CLIENT_TYPE_SLAVE 1 /* Slaves. */ +#define CLIENT_TYPE_PUBSUB 2 /* Clients subscribed to PubSub channels. */ +#define CLIENT_TYPE_MASTER 3 /* Master. */ +#define CLIENT_TYPE_OBUF_COUNT 3 +``` + +**枚举** 使用前缀: +``` +enum conn_states { + conn_listening, /**< the socket which listens for connections */ + conn_new_cmd, /**< Prepare connection for next command */ + conn_waiting, /**< waiting for a readable socket */ + conn_read, /**< reading in a command line */ + conn_parse_cmd, /**< try to parse a command from the input buffer */ + conn_write, /**< writing out a simple response */ + conn_nread, /**< reading in a fixed number of bytes */ + conn_swallow, /**< swallowing unnecessary bytes w/o storing */ + conn_closing, /**< closing this connection */ + conn_mwrite, /**< writing out many items sequentially */ + conn_closed, /**< connection is closed */ + conn_max_state /**< Max state value (used for assertion) */ +}; +``` + +**函数命名** 全小写,单词之间"_"分割。如"split_cmdline_strerror()" + + +### 注释 + +所有注释使用 "/* 这里是注释 */ " + + +### 其他 + +合理使用static,const 等关键字,能提升程序的安全性,也能避免函数命名冲突 +合理使用数据类型:rel_time_t,uint8_t,uint32_t,uint64_t,size_t,off_t