问题描述
当我遇到LARGE_INTEGER的定义时.我发现一些问题:
When I come across the definition of LARGE_INTEGER. I find some questions:
typedef union _LARGE_INTEGER {
struct {
DWORD LowPart;
LONG HighPart;
} DUMMYSTRUCTNAME;
struct {
DWORD LowPart;
LONG HighPart;
} u;
LONGLONG QuadPart;
} LARGE_INTEGER;
我们可以重写如下吗?
typedef union _LARGE_INTEGER {
struct {
DWORD LowPart;
LONG HighPart;
} DUMMYSTRUCTNAME;
LONGLONG QuadPart;
} LARGE_INTEGER;
我认为结构u是重复的.那么,为什么MSVC这样实现LARGE_INTEGER?我想知道也许有些原因,例如兼容性.
I think the struct u is duplicate. So why MSVC implement LARGE_INTEGER as this? I wonder maybe some reason like compatibility.
推荐答案
显然,这是为了避免在联盟中具有匿名结构,这是一种调整.Visual C ++已支持此功能,但语言标准不允许这样做.(请参见无法理解LARGE_INTEGER结构,以了解没有DUMMYSTRUCTNAME
.)将添加该名称,以使并集与标准C ++(可能与某种自动化工具)保持一致.
It is apparently an adjustment to avoid having an anonymous structure in a union. This had been supported by Visual C++, but is not allowed in by the language standard. (See can't make sense of LARGE_INTEGER struct for a declaration of the struct without the DUMMYSTRUCTNAME
.) The name would have been added to bring the union into conformance with standard C++, possibly with some sort of automated tool.
最新版本 LARGE_INTEGER
完全摆脱了结构,只有 QuadPart
.
Later versions of LARGE_INTEGER
get rid of the structs entirely and just have the QuadPart
.
这篇关于LARGE_INTEGER和DUMMYSTRUCTNAME的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!