fusion/common/standard.c

89 lines
2.9 KiB
C
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*************************************************
1. 头文件说明
File name : app_main.c
Module :
Author : amir
Version : 0.1
Created on : 2022-02-11
Description : 代码语法规范
Modify History:
1. Date: Author: Modification:
*************************************************/
#include <stdint.h>
#include "hlog.h"
/*[0]超过512字节的内存考虑要用堆内存, 特别是1K及以上禁止用栈内存*/
/*2. 注释标准:头文件宏标准*/
#ifndef __MAIN_H__ /* 3. 双下线__ */
#define __MAIN_H__
#endif
#define MAX(a, b) ((a) > (b) ? (a) : (b)) /* 4. 变量用括号() */ /* 注释用 *号进行,避免用 // */
#define MIN(a, b) ({int32_t ret; ret = (a) > (b) ? (b) : (a); ret+2;}) /* 5. 定义变量得到其值GNU支持({}), 其它代替do{}while(0) */
#define MAX_PATH (256) /* 6. 宏用大写*/
typedef enum {
STD_OK,
STD_NG,
}std_e; /* 7. 结构体 _e */
typedef struct {
uint8_t num; /* 8. num of pipeline -- 变量简明注释,特别是重要的变量 */
std_e e_std;
}std_s; /* 9. 结构体 _s */
static int32_t s_num; /* 10. 静态变量用 s_xxx */
static int32_t g_num; /* 11. 全局变量用 g_xxx, 尽量少用公共变量 ,全局变量减少耦合 */
static int32_t k_num; /* 12. 常量用 k_xxx */
static int32_t *p_num; /* 13. 指针变量用 p_xxx */
#define OK 0 /* 14. success */
#define NG 1 /* fail */
int32_t standard(void) { /* 15. 函数 花括号*/
hloge("<< %s %d", __func__, MIN(1,5));
return OK; /* 16. TAB键为4个空格 */
}
/* 17. <---- 函数间用空格分段 */
int32_t standard2(std_s *p_std) {/* 18. 1. 对于结构体入参尽可能用指针2. 指针变量用 p_xxx, 3. 指针符号*靠近变量 */
int32_t k = 1; /* 19. 不允许将多个短句放一行 */
uint32_t i = 0; /* 20. =号对齐 */
char *p_str = NULL; 0; /* 21. 变量或指针要尽量初始化,除非明确操作 */
{
uint8_t cnt = 0; /* 22. 变量靠近第一次使用处 */
cnt = cnt+cnt+cnt+cnt+cnt+cnt+cnt+cnt+cnt+cnt+cnt+cnt+cnt
+cnt; /* 23. 操作符放在新行首 */
}
switch ( i ) { /* 24. switch/while/if/for/do 独占一行,需要加花括号, 加空格,突出关键字 */
case 1:
break;
case 2:
break;
default:
break;
}
i = i + 1; /* 25. 操作符前面加空格 */
i += 1; /* 26. 选号对齐 */
if ( i > k ) {/* 27. i不能小于k -- while/if/for 写注释,有助于维护人员 */
k = ( i + k ) / 10; /* 28. 用括号表明操作顺序 */
}
#ifdef MAX_PATH
{ /* 29. 宏花括号 */
hlogi("<< %s MAX_PATH:%d", __func__, MAX_PATH);
}
#endif
return OK; /* 30. 用宏或有意义的变量表达, 禁止使用magic num */
}