Win32 API 数据类型命名约定指南
我是使用 Win32 API 进行编程的新手,并且仍在习惯前缀/后缀数据类型命名约定。虽然谷歌和一点常识通常会解释前缀所指的内容,但如果有一个(相对)简洁的指南来解释它们,那就太好了。有人知道这样的资源吗?
相关说明,“_”(下划线)前缀对于变量意味着什么?除了“下划线”之外,该下划线还有其他名称吗?
I'm new to programming with the Win32 API, and I'm still getting used to the prefix / suffix data type naming conventions. While Google and a little common sense will normally explain what the prefix is referring to, it would be nice if there was one (relatively) concise guide to explain them. Does anyone know of a resource like this?
And on a related note, what does the '_' (underscore) prefix mean with a variable? Does that underscore have a name, other than "underscore"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如其他人提到的,命名约定称为匈牙利表示法。由于您不熟悉它,并且可能会开始使用它,因此值得一提的是,匈牙利语有两种主要风格:在
例如,当使用 int 来描述某个字符串中的字节数时,差异就很明显 对于前者,将使用 nLen,这意味着变量是 int。后者将使用 cbLen,这意味着变量对字节进行计数(与 cchLen 不同,cchLen 对字符进行计数)。看看这篇文章,应该会给你更好的解释。
至于变量或函数前面的下划线 - 这是为编译器及其标准库保留的命名约定。有些人将其用于其他目的,但他们确实不应该这样做。该约定的目的是为编译器提供命名标准,以防止与用户给出的名称发生冲突。
The naming convention is called Hungarian Notation, as mentioned by others. Since you're not familiar with it, and are probably going to start using it, it is worth mentioning there are two main flavors of Hungarian:
The difference is visible when, for instance, an int is used to describe the number of bytes in a certain strings. On the former, nLen will be used, meaning the variable is an int. On the later, cbLen will be used, meaning the variable counts bytes (as opposed to cchLen, which counts characters). Give this article a look, should give you a better explanation.
As for the underscores in front of a variable or function - this is a naming convention reserved for the compiler and its standard library. Some people use it for other purposes, but they really shouldn't. The purpose of the convention is to provide the compiler a naming standard that will prevent collisions with names given by the user.
Win32 API 遵循匈牙利表示法
Win32 API follows Hungarian Notation
它被称为匈牙利表示法,维基百科有一些关于它的信息,并且有MSDN 上的内容。
It's called a hungarian notation, Wikipedia has some information about it, and there's something on MSDN.