本文介绍了Windows数据类型...为什么这么冗余/ undescriptive?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能有人请正是为什么以下的typedef S / 的#define 活动的定义?他们有什么价值,相对于原稿?

Could someone please exactly why the following typedefs/#defines have been defined? What value do they have, compared to the originals?

typedef char CHAR;
#define CONST const
typedef float FLOAT;

typedef unsigned __int64 DWORD64; //A 64-bit "double"-word?!
typedef ULONGLONG DWORDLONG;      //What's the difference?

typedef ULONG_PTR DWORD_PTR;      //What's the difference?
typedef long LONG_PTR;            //Wasn't INT_PTR enough?

typedef signed int LONG32;        //Why not "signed long"?
typedef unsigned int UINT;        //Wait.. UINT is "int", "LONG" is also int?
typedef unsigned long ULONG;      //ULONG is "long", but LONG32 is "int"? what?

typedef void *PVOID;              //Why not just say void*?
typedef void *LPVOID;             //What?!

typedef ULONG_PTR SIZE_T;         //Why not just size_t?

和,最重要的是:

#define VOID void                 //Assuming this is useful (?), why not typedef?

什么是这背后的理由?它是某种抽象的,我不理解?

What's the reasoning behind these? Is it some sort of abstraction I'm not understanding?

修改

有关的人提的编译器交叉compatilibity:

For those people mentioning compiler cross-compatilibity:

我的问题是的的,为什么他们没有使用无符号长长而不是,比方说, DWORD64 。我的问题是,为什么会有人用 DWORD64 而不是 ULONG64 (反之亦然)?是不是这两个的typedef ED的是64位的?

My question is not about why they didn't use unsigned long long instead of, say, DWORD64. My question is about why would anyone use DWORD64 instead of ULONG64 (or vice-versa)? Aren't both of those typedefed to be 64 bits wide?

或者,作为另一个例子:即使在是为了欺骗我们在各方面一个假设的编译器,这将是 ULONG_PTR之间的差异 UINT_PTR DWORD_PTR ?是不是所有的那些抽象数据类型只是意味着同样的事情? - SIZE_T

Or, as another example: Even in a "hypothetical" compiler that was meant to deceive us in every respect, what would be the difference between ULONG_PTR and UINT_PTR and DWORD_PTR? Aren't those all abstract data types just meaning the same thing -- SIZE_T?

不过,我的上午的问,为什么他们用 ULONGLONG 而不是长长 - - ?有没有意义的电位差,既没有覆盖长长也不 DWORDLONG

However, I am asking why they used ULONGLONG instead of long long -- is there any potential difference in meaning, covered by neither long long nor DWORDLONG?

推荐答案

大部分多余的名字的存在主要有两个原因:

Most of these redundant names exist primarily for two reasons:


  • 他们的历史类型的向后兼容性preserved

  • 他们对于从开发商不同的球队出现了同一类型不同的名字(也可以是相当困难的团队仍然在如此庞大的计划与Windows一致)

typedef char CHAR;

字符的符号性可以跨平台和编译器有所不同,所以这是原因之一。最初的开发者可能也一直在这个开放的字符编码​​的未来变化,当然这已经不再重要,因为我们使用 TCHAR 现在用于这一目的。

The signedness of char can vary across platforms and compilers, so that's one reason. The original developers might have also kept this open for future changes in character encodings, but of course this is no longer relevant since we use TCHAR now for that purpose.

typedef unsigned __int64 DWORD64; //A 64-bit "double"-word?!

在迁移到64位,他们可能发现一些真正需要的是64位长的 DWORD 参数,并且他们可能更名为 DWORD64 ,使这些API的现有用户不混淆。

During the move to 64-bit, they probably discovered that some of their DWORD arguments really needed to be 64 bits long, and they probably renamed it DWORD64 so that existing users of those APIs weren't confused.

typedef void *PVOID;              //Why not just say void*?
typedef void *LPVOID;             //What?!

这其中的历史可以追溯到16位的日子里,当有是16位,并且是32位的远指针经常近指针。在 preFIX的类型代表长或远,现在是没有意义的,但在那些日子里,这些很可能是这样定义的:

This one dates back to the 16-bit days, when there were regular "near" pointers which were 16-bit and "far" pointers that were 32-bit. The L prefix on types stands for "long" or "far", which is meaningless now, but back in those days, these were probably defined like this:

typedef void near *PVOID;
typedef void far *LPVOID;


更新:至于 FLOAT UINT ULONG ,这些只是例子更抽象好,鉴于未来的变化。请记住,Windows还运行在x86之外的平台 - 你能想到的地方浮点数被重新在非标准格式和API函数psented $ P $进行了优化,利用这个重新$的架构p $ psentation。那么这可能是用C的浮法冲突数据类型。


Update: As for FLOAT, UINT and ULONG, these are just examples of "more abstraction is good", in view of future changes. Keep in mind that Windows also runs on platforms other than x86 -- you could think of an architecture where floating-point numbers were represented in a non-standard format and the API functions were optimized to make use of this representation. This could then be in conflict with C's float data type.

这篇关于Windows数据类型...为什么这么冗余/ undescriptive?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 20:15