当前位置:网站首页>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
边栏推荐
- CUDA project encountered a series of compilation problems after changing the environment (computer)
- 服务器常见错误代码 总结
- FOC电机库 定点PID代码分析
- Krypton zeal
- v-for下定时给图片添加动画
- Shell脚本 &&和||的使用
- 基于VGG卷积神经网络的图像识别代码实现
- Introduction and application of WMI Technology
- Assembler 32-bit unsigned addition calculator
- Multibyte and Unicode in VS
猜你喜欢
随机推荐
卷积神经网络实现CIFAR100数据集分类
欢迎使用Markdown编辑器
ARM常用汇编指令
[UDS] unified diagnostic service (UDS)
File viewing commands and user management commands
[UDS unified diagnosis service] IV. typical diagnosis service (3) - read fault information function unit (storage data transmission function unit)
Palindromic Primes
HDU-Memory Control
CUDA environment installation
基于VGG卷积神经网络的图像识别代码实现
[opencv] use filestorage to read and write eigenvectors
【UDS统一诊断服务】一、诊断概述(2)— 主要诊断协议(K线和CAN)
产生随机数
QT add qserialport class to realize serial port operation
Figure guessing game
说说ts的心里话
FOC SVPWM函数PWMC_SetPhaseVoltage解析
JS中 t, _ => 的解析
Opencv uses genericindex for KNN search
锚点定位——如何设置锚点居页面顶部距离,锚点定位并距离顶部一定偏移