Sign in to follow this  
cqulyx

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

Recommended Posts

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.)? Thanks in advance.

Share this post


Link to post
Share on other sites
There are two possible answers. Firstly, backwards compatibilty. Previous versions of the Win32/16 API may not have had the LONGLONG member. Secondly, not all compilers supported the anonymous structure, so again, for compatibility the legacy is left in. The 'u' probably means 'union' as in 'part of a...'.

Skizz

Share this post


Link to post
Share on other sites
The original version was the struct u version. Later on when support for anonymous structs inside unions came along the other version was added for convienence. The old version couldn't be removed because by that time tons of code had been written for it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this