Re: Why does Platform SDK define union LARGE_INTEGER in such a way?



"Lighter" wrote:
Why does Platform SDK define union LARGE_INTEGER in such a way?

ntdef.h defines the union LARGE_INTEGER as follows:

typedef union _LARGE_INTEGER
{
struct
{
ULONG LowPart;
LONG HighPart;
};

struct
{
ULONG LowPart;
LONG HighPart;
} u;

LONGLONG QuadPart;
} LARGE_INTEGER;

Though I fully understand what union is, I cannot think out the reason
why it adds struct u into the union. In fact, the struct u is
equivalent to the unnamed struct, so we can alway use the unnamed
struct instead of struct u. To my thinking, the union should be
designed as follows:

typedef union _LARGE_INTEGER
{
struct
{
ULONG LowPart;
LONG HighPart;
};

LONGLONG QuadPart;
} LARGE_INTEGER;

Am I right?

Who can tell me what the consideration for the former definition is,
and what does it mean by the struct name "u" (means "unsigned" ?, I'm
not sure.)?


I think, in the beginning LARGE_INTEGER was defined as you described. Then Platform SDK team discovered that not all compilers (or compiler switches) will be able to handle unnamed nested struct. So, they added `u' member.

.