Win32 API 数据类型命名约定指南

发布于 2024-08-05 13:50:01 字数 166 浏览 4 评论 0原文

我是使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

jJeQQOZ5 2024-08-12 13:50:01

正如其他人提到的,命名约定称为匈牙利表示法。由于您不熟悉它,并且可能会开始使用它,因此值得一提的是,匈牙利语有两种主要风格:在

  1. 变量前添加其类型代码
  2. 前缀,在变量前添加其< 。

例如,当使用 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:

  1. prefix the variable with its type code
  2. prefix the variable with its usage code

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.

听风念你 2024-08-12 13:50:01

Win32 API 遵循匈牙利表示法

Win32 API follows Hungarian Notation

删除会话 2024-08-12 13:50:01

它被称为匈牙利表示法,维基百科有一些关于它的信息,并且有MSDN 上的内容

It's called a hungarian notation, Wikipedia has some information about it, and there's something on MSDN.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文