473,659 Members | 2,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.

Oct 6 '06 #1
3 8789

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.)?
Thanks in advance.
Oh, another guy works in Windows. See the following link:

http://msdn.microsoft.com/library/de...nteger_str.asp

.. Ask a programmer who works for Microsoft. Maybe they think of
compatibility.

Oct 6 '06 #2
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
The tag name is reserved for implementation use. I think you're showing
a file from your implementation, in which case it is free to use these
reserved names, as well as non-standard features that may be provided.
{
struct
{
ULONG LowPart;
LONG HighPart;
};
Unnamed union members are not available in standard C.
>
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:
No, the unnamed struct is illegal in standard C. If you want to write
standard C, leave out the unnamed struct and keep u. If you want to
write non-standard C, move to a platform-specific newsgroup.
typedef union _LARGE_INTEGER
{
struct
{
ULONG LowPart;
LONG HighPart;
};
LONGLONG QuadPart;

} LARGE_INTEGER;
Am I right?
No, this suffers from the same problem. You removed the wrong struct.
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 suppose, on compilers that allow unnamed struct members of unions, it
gives the user an option whether to write

LARGE_INTEGER i; i->u->LowPart = 0xFFFFFFFF;

or

LARGE_INTEGER i; i->LowPart = 0xFFFFFFFF;

--
Simon.
Oct 6 '06 #3
"Lighter" <cq****@gmail.c omwrites:
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;
Because the author(s) of that code don't care about portability. The
identifer _LARGE_INTEGER is reserved to the implementation (perhaps
the Platform SDK is part of the implementation? ). Anonymous members
are not legal in standard C. The code assumes that the low-order half
is stored at the lowest address.

The typedefs (or are they macros?) ULONG, LONG, and LONGLONG are,
IMHO, horribly bad style. If they're always aliases for unsigned
long, long, and long long respectively, then the code should use
unsigned long, long, and long long. If they might sometimes refer to
other types, then the names ULONG, LONG, and LONGLONG are misleading.

Leaving that aside, I suppose the idea is that you can declare

LARGE_INTEGER x;

and then refer to the numeric value as x.QuadPart, and to the
low-order half as either x.LowPart (non-portably) or x.u.LowPart
(portably, if you drop the anonymous structure from the union
declaration), and likewise for the high-order half.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Oct 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
12553
by: Alessandro Crugnola *sephiroth* | last post by:
hi, i have already problems using py2exe.. i'm using python 2.2, wxPython and audiere for a little mp3 player.. once I've build the exe with py2exe, when launching the application: Traceback (most recent call last): File "<string>", line 9, in ? File "imputil.pyc", line 103, in _import_hook File "<string>", line 52, in _import_top_module
2
6755
by: Chris Hodapp | last post by:
I have seen messages posted about this before, and there is a clear reference to it in the manual, but I have been unable to find a solution. I'm on Slackware 9.1, kernel 2.6.0-test11, using Python 2.3.1 and GCC 3.2.3 (both installed by default with Slackware) and SWIG 1.3.19, compiled from source code. I messed around a little on my own and couldn't get things to work right, so I copied the examples from the book, nearly verbatim but...
2
1647
by: Christian Seberino | last post by:
I created a C extension that works in Linux great. I tried to make a DLL of it and got an error that didn't happen in Linux... >>> import peak_load Traceback (most recent call last): File "<stdin>", line 1, in ? ImportError: dynamic module does not define init function (initpeak_load) I can see initpeak_load in my C code!!! Linux can see it!!!
0
2755
by: Bill Davy | last post by:
Hello, I am using SWIG-1.3.24 to make an extension (called SHIP) to Python2.4.1 and then running under IDLE (if that makes any difference) but when I "import SHIP" I get: >>> import SHIP Traceback (most recent call last): File "<pyshell#0>", line 1, in -toplevel-
0
2708
by: Bill Davy | last post by:
I am working with MSVC6 on Windows XP. I have created an MSVC project called SHIP I have a file SHIP.i with "%module SHIP" as the first line (file is below). I run SHIP.i through SWIG 1.3.24 to obtain SHIP_wrap.cpp and SHIP.py; the latter contains the line "import _SHIP". I compile SHIP_wrap.cpp and a bunch of files into a DLL which I have the
5
14020
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to VIS.DLL via Visual Studio, with no problems: ------ Rebuild All started: Project: VIS, Configuration: Debug .NET ------ Preparing resources... Updating references...
4
449
by: Lighter | last post by:
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;
22
3283
by: David T. Ashley | last post by:
I'm writing code which will compile on multiple Windows and multiple *nix platforms. Some will have 64-bit integers, I believe. What is my best option to define platform-independent types such as UINT32 or UINT64? I'm not sure how to sort out the various platforms and integer sizes, and some of it may even vary based on compiler options. Thanks -- David T. Ashley (dta@e3ft.com)
1
9994
by: JeanDean | last post by:
I have successfully installed the valgrind-3.2.3 but it is resulting in following error ------------------------- valgrind ls -l valgrind: failed to start tool 'memcheck' for platform 'x86-linux': No such file or directory -------------------------- Any sort of suggestion will be appreciated .
1
8525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.