STM32开发笔记97: C++语言命名规范

单片机型号:STM32F091RCT6


在此文章中记录C++语言的命名规范。

1、文件名均采用小写英文字母方式实现,多个英文单词之间用“_"予以分割;

2、宏定义均采用大写英文字母方式实现,多个英文单词之间用“_"予以分割;

3、自定义数据类型均小写英文字母方式实现,多个英文单词之间用“_"予以分割;

4、类名首字母用C表示,后续采用匈牙利命名法,首字母大写,如遇英文缩写单词,则按照英文命名规范进行拼写,例如LED为缩写单词,但是英文规范可以写作led或Led,则类名用CLed表示,而HAL是硬件映射层的缩写,英文用全大写表示,使用时,则使用CHAL命名;

5、用类声明的类对象,去除首字母C即可,例如CLed命名的对象,则直接为Led;

6、变量名按照匈牙利表示法进行表示,以前缀开头,前缀后加“_”,后面用多个英文单词准确表示变量实际含义,单词首字母大写,如遇英文缩写单词,按照英文书写规范进行拼写,例如ms为缩写单词,英文用小写表示,则变量名为u16_ms;

7、变量名为bool型的,前面加b作为前缀,后面不加“_”,例如bMilliSecond_1000,bResult等,

8、变量名如为复合型的数据类型,如结构体、联合、枚举等,可不加前缀进行命名;

9、指针型变量,可以采用前缀p,后面不加“_”,例如pData。

10、单行注释使用“//”加1个空格表示,例如“// 主函数”;

11、以下是VS Code中,设置都文件与CPP文件的用户代码片段信息:

{
	"Structure information for .h file": {
		"prefix": "Structure for .h file",
		"body": [
	 		"/**",
			"******************************************************************************",
			"* @file        .h",
			"* @brief        头文件",
			"* @author      snmplink",
			"* @version     使用Git进行版本控制",
			"* @date        2020-  创建该文件",
			"******************************************************************************",
			"* @attention",
			"*",
			"* <h2><center>&copy; Copyright (c) 2020-2030 snmplink.",
			"* All rights reserved.</center></h2>",
			"*",
			"* 开发文档:https://snmplink.blog.csdn.net/",
			"* ",
			"* github:https://github.com/snmplink",
			"* ",
			"* 码云:https://gitee.com/snmp123452",
			"* ",
			"* License. You may obtain a copy of the License at:",
			"*                        opensource.org/licenses/BSD-3-Clause",
			"*",
			"******************************************************************************",
			"*/",
			"",
			"#ifndef _H_",
			"#define _H_",
			"",
			"#include \".h\"",
			"",
			"#ifdef __cplusplus",
			"extern \"C\"{",
			"#endif",
			"",
			"class ",
			"{",
			"public:",
			"",
			"};",
			"",
			"#ifdef __cplusplus",
			"}",
			"#endif",
			"#endif"
		],
		"description": "头文件结构信息"
	},
	
	"Structure information for .cpp file": {
		"prefix": "Structure for .cpp file",
		"body": [
	 		"/**",
			"******************************************************************************",
			"* @file        .cpp",
			"* @brief        源文件",
			"* @author      snmplink",
			"* @version     使用Git进行版本控制",
			"* @date        2020-  创建该文件",
			"******************************************************************************",
			"* @attention",
			"*",
			"* <h2><center>&copy; Copyright (c) 2020-2030 snmplink.",
			"* All rights reserved.</center></h2>",
			"*",
			"* 开发文档:https://snmplink.blog.csdn.net/",
			"* ",
			"* github:https://github.com/snmplink",
			"* ",
			"* 码云:https://gitee.com/snmp123452",
			"* ",
			"* License. You may obtain a copy of the License at:",
			"*                        opensource.org/licenses/BSD-3-Clause",
			"*",
			"******************************************************************************",
			"*/"
		],
		"description": "CPP源文件结构信息"
	}
}

 

 

 

发布了425 篇原创文章 · 获赞 1113 · 访问量 83万+

猜你喜欢

转载自blog.csdn.net/qingwufeiyang12346/article/details/104133409