C代码中的命名方式总结和改进
- 宏全部使用大写字母--------宏大写
- 结构体名字全部使用typedef,typedef之后的名字为大写-------结构体别名大写
- 函数名全部使用小写字母,单词之间使用下划线分割-------函数名小写,单词之间下划线(1)
- 函数名第一个单词全小写,后面单词的首字母大写,单词之间使用下划线---------函数名首单词小写,后面单词首字母大写(2)
- 变量名也是全部使用小写,单词之间使用下划线分割-------变量名小写,单词之间下划线(1)
- 变量名第一个单词全小写,后面单词的首字母大写,单词之间使用下划线---------变量名单词小写,后面单词首字母大写(2)
变量的命名前后缀规则如下(这是匈牙利命名法的前后缀格式,以后其他地方使用上述的总结,前后缀使用匈牙利的):
The type prefix indicates the data type of the variable.
Type prefix | Meaning | Example |
---|---|---|
b | boolean | bool bHasEffect; |
c (or none*) | class | Creature cMonster; |
ch | char (used as a char) | char chLetterGrade; |
d | double, long double | double dPi; |
e | enum | Color eColor; |
f | float | float fPercent; |
n |
short, int, long char used as an integer |
int nValue; |
s | struct | Rectangle sRect; |
str | C++ string | std::string strName; |
sz | Null-terminated string | char szName[20]; |
The following type modifiers are placed before the prefix if they apply:
Type modifier | Meaning | Example |
---|---|---|
a | array on stack | int anValue[10]; |
p | pointer | int* pnValue; |
pa | dynamic array | int* panValue = new int[10]; |
r | reference | int rnValue; |
u | unsigned | unsigned int unValue; |
The following scope modifiers are placed before the type modifier if they apply:
Scope modifier | Meaning | Example |
---|---|---|
g_ | global variable | int g_nGlobalValue; |
m_ | member of class | int m_nMemberValue; |
s_ | static member of class | int s_nValue; |
补充:
- p ---------for a pointer. A pfoo would be a pointer to data item of type FOO
- pp------- for a pointer to a pointer.
- h --------for a heap handle. This is a pointer to a pointer that points at a data item recorded within a heap.
- rg -------for an unstructured array containing data items of a certain data type. An rgfoo would be an array that contains data of type foo. Individual elements would be selected by an ifoo index variable.
- mp -------for an array which is used to map from one data type to another.Eg. A mpdochdod would be indexed via a doc index. The expression mpdochdod[doc] would produce a handle to a document descriptor.
- dn-------- for an array whose elements that describes a meaningful index such as an opcode. If the meaningful index were an OP type, a data structure of type EOP (entries for OP) would be defined, and a dnop array would be defined which describes what each individual op means
Max - added to an index data instance which records the actual size of an array or data block.
eg. the declaration of a an array of type FOO in C would be: FOO rgfoo[ifooMax];
Mac - added to an index data instance to indicate the limit of an actual usage within an array.Mac stands for current maximum. It is invariant that ifooMac <= ifooMax. ifooMac == ifooMax is the condition which is true when all entries within an array are in use.
First - added to an index or pointer which designates the first element within a range that may be validly processed
Last - added to an index or pointer which designates that last entry within a range that may be validly processed.
Lim - stands for limit. An ifooLim is equal to ifooLast + 1 and designates the location where a new foo item could be recorded in an array or data block.
转载于:https://www.cnblogs.com/jack204/archive/2011/09/07/2170408.html
C代码中的命名方式总结和改进相关推荐
- php中嵌套html代码和html代码中嵌套php方式
php中嵌套html代码和html代码中嵌套php方式 一.总结 拷贝的话直接html代码是极好的方式 1.php中嵌套html代码(本质是原生php):a.原生嵌套<?php .....?&g ...
- c语言中一般命名方式,C语言常见命名规则
1 常见命名规则 比较著名的命名规则首推匈牙利命名法, 这种命名方法是由Microsoft程序员查尔斯·西蒙尼(Charles Simonyi) 提出的. 其主要思想是"在变量和函数名中加入 ...
- 一文搞定代码中的命名
导语 Phil Karlton 曾经说过:计算机科学领域只有两件难事:缓存失效和命名.而命名又是写出整洁代码基础中的基础,本文的副标题其实是<关于命名的读书笔记>,自己在学习过程中的整理出 ...
- 问答:如何规划CSS 中 的命名方式 如何看待 CSS 中 BEM 的命名方式?
好多盆友 很纠结 css命名规则 怎么弄,还没起步就被绊住了,那么今天蝈蝈就针对这个问题来讨论一下 没什么技术 含量,但却对效率开发至关重要的 "问题". 下文是一些知乎大神的个人 ...
- 写自动化测试代码中的命名规范
文章目录 前言 规范 前言 本人用 java 的自动化举例 规范 在写 java 的 UI 自动化代码脚本时候,对于测试用例类,我们可以用XxxTest的方式命名 对于测试类中的测试方法,可以用tes ...
- Android代码中实现WAP方式联网
无论是移动.联通还是电信,都至少提供了两种类型的的APN:WAP方式和NET方式.其中NET方式跟WIFI方式一样,无需任何设置,可自由访问所有类型网站,而WAP方式,需要手机先设置代理服务器和端口号 ...
- 编程中的命名方式和常用命名名称
名字要完全.准确地描述出该变量所代表的事物 用名字表达变量所代表的是什么,不包含晦涩的缩写,无歧义 目前命名方法有以下几种: 1.驼峰法 小驼峰:第一个单词小写,其他单词首字母大写: 写法如:myFi ...
- 编写高质量可维护的代码:优雅命名
大家好,我是若川.今天分享一篇关于如何命名更优雅的文章. 点击下方卡片关注我.加个星标,或者查看源码等系列文章.学习源码整体架构系列.年度总结.JS基础系列 本文首发于政采云前端团队博客:编写高质量可 ...
- C++ 命名方式建议
文章目录 1.目录与文件命名 2.类型命名 3.名字空间命名 4.函数命名 5.变量命名 6.枚举与宏命名 7.小结 参考文献 一个大型项目,参与开发人员众多,每个人的编码风格迥异,为保持代码风格统一 ...
最新文章
- Zigbee系列(概览)
- 浏览器history操作实现一些功能
- android编程获取网络和wifi状态及调用网络设置界面,Android编程获取网络连接状态(3G/Wifi)及调用网络配置界面 - Android平台开发技术 - 博客园...
- Ubuntu开机自动启动script(2)
- python3.6生成exe_Python 3.6打包成EXE可执行程序的实现
- 图像目标分割_5 DeepLab V2 V3 V3+
- python之质数判断
- osm数据导入mysql_OSM(OpenStreetMap) poi、路网 数据导入 PostgreSQL
- 【elasticsearch】ES 相似文章检测
- 解决使用elementUI框架el-upload上传组件时session丢失问题
- Flink 新一代流计算和容错——阶段总结和展望
- String s = new String(“abc“)创建了几个对象
- MISC图片隐写之foremost
- 显卡dos测试软件,A+N卡测试说明_早期显卡DOS版本
- php怎么文字加粗体代码,html字体加粗用css设置文字粗体样式
- Ps光速制作文字矢量图
- com.android.stfwd,[原创]360freewifi逆向分析
- 什么是PPI,有什么作用?
- 插入栈顶元素c语言,详解数据结构之顺序栈的基本操做(C语言描述)
- 香港 - 寻找轻鬆攻略游(蒲台岛)