当前位置:网站首页>C language code specification
C language code specification
2022-04-23 06:47:00 【tilblackout】
(1)switch case
swich
and case
Labels should be aligned in the same column
switch (character) {
case 'a':
...
break;
default:
break;
}
(2) The length of a line is limited to 80 Column
More than a line break , And indent appropriately , Usually an indentation is enough .
(3) Brackets
Curly braces are used in the code {}
The place of , You should put the starting brace “{” Put it at the end of the line , Put the closing braces “}” Put it at the beginning of the line . Such as if
、switch
、for
、do
、while
.
- Be careful : The starting brace of the function should be placed at the beginning of the next line
When there is only one single statement, do not enlarge the parentheses :
if (condition)
action();
// Multi branch case : As long as a branch is not a separate statement, it should be bracketed
if (condition) {
do_this();
do_that();
} else {
otherwise();
}
(4) Space
- Do not add spaces after unary operators , Such as
*
( The pointer )、!
、~
、sizeof
- Binary operators ( Both sides are followed by operands ) You need to add a space on both sides , Such as
*
( Multiplication )、=
、!=
、==
、%
- In pointer type ,
*
It should be close to the variable name or function name , Not close to the type name .
(5) notes
Comments should tell others what the code does , Not how to do it . Comments should be placed at the head of the function , And... Should be selected /* ……… */
, instead of //
.
For multiline comments , It should be like this :
/*
* This is the preferred style for multi-line
* Please use it consistently.
*/
File information notes ( Put it at the beginning of the file ):
/*************************************************
Copyright zuozhongkai Co., Ltd. 1998-2018. All rights reserved.
File name: // file name
Author: // author
Version: // Version number
Description: // Used to specify the main functions of this program file , With other modules
// Or function interface , Output value 、 Value range 、 The control between meaning and parameters
// system 、 The order 、 Independence or dependence, etc
Others: // Description of other contents
Log: // Modification log , Including the modification of the content , date , Modifier, etc
*************************************************/
Comments on functions :
/*
* @Description: Function description , Describe the basic functions of this function
* @param 1 – Parameters 1.
* @param 2 – Parameters 2
* @return – Return value
*/
(6) Naming rules
- Words in lowercase , Then underline each word “_” come together (Linux Naming style )
- Use complete words or abbreviations that everyone knows
- Variables with mutually exclusive meaning or functions with opposite actions should be named with mutually exclusive phrases
(7) function
- A function completes a function
- Duplicate code should be refined into functions
- Different functions are separated by empty lines , If you need to export ,
EXPORT*
Macro should stick close to his end
Under braces
int system_is_up(void)
{
return system_state == SYSTEM_RUNNING;
}
EXPORT_SYMBOL(system_is_up);
- If there are multiple loops in a function , Or exit from multiple locations , It is recommended to use
goto
- Function nesting should not exceed 4 layer
- Check the validity of the parameters of the function
- Only the functions used in the current file should be added
static
(8) macro
- The name of the macro that defines the constant and the label in the enumeration should be capitalized , But function macros can be lowercase
- A macro that uses an expression to define a constant must place the expression within a pair of parentheses , Such as
#define CONSTEXP (CONSTANT | 3)
- For macros with multiple statements , The proposal is written as
do while(0)
Format - If the macro is a constant , It is recommended to use
const
Instead of
版权声明
本文为[tilblackout]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230549283010.html
边栏推荐
- Informatics one book pass - small ball
- CUDA环境安装
- Analysis and setting of dead time
- C [document operation] PDF files and pictures are converted to each other
- cv_bridge 与opencv 版本不匹配的解决
- Eigen 学习总结
- [UDS unified diagnostic service] II. Network layer protocol (1) - overview and functions of network layer
- POJ-The Unique MST
- Understanding of SSH public key and private key
- [UDS unified diagnostic service] IV. typical diagnostic service (5) - function / component test function unit (routine function unit 0x31)
猜你喜欢
随机推荐
sqlite3加密版
undefined reference to `Nabo::NearestNeighbourSearch
JS中 t, _ => 的解析
[UDS unified diagnosis service] i. diagnosis overview (3) - ISO 15765 architecture
2022ldu winter vacation training - program patch
生成快捷方式
Qt 给应用程序加图标
Round up a little detail of the round
Matlab calibration board corner detection principle
微信小程序之点击取消,返回上页,修改上页的参数值,let pages=getCurrentPages() let prevPage=pages[pages.length - 2] // 上一页的数据
C语言进阶要点笔记4
死区时间的分析与设置
Log writing method (with time)
Eigen 库常用基本用法 备忘
逻辑回归原理及代码实现
PHP junior programmers, take orders and earn extra money
Figure guessing game
[UDS unified diagnostic service] i. overview of diagnosis (4) - basic concepts and terms
Makefile基础、常用函数及通用Makefile
Notes on advanced points of C language 4