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



"Lighter" <cqulyx@xxxxxxxxx> writes:
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_Keith) kst-u@xxxxxxx <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.
.



Relevant Pages

  • Re: bitwise on float
    ... union kludge { ... You can then store a double value in the "d" member, ... Well, if you're going to declare it like that, then apparently writing ... struct double_rep { ...
    (comp.lang.c)
  • Re: Defining a union in ANSI/ISO C?
    ... control information data contains a union that describes things like ... If I can declare the latter as static, ... Perhaps you could try a struct that contains a union member? ...
    (comp.os.msdos.programmer)
  • Re: Yet another free() question.
    ... fields of your struct A and struct B will be laid out consistently, ... unless you happen to declare a union of the two types, ... It's particularly difficult to imagine in the case of separate ... a union of them might be declared in some other file. ...
    (comp.lang.c)
  • Re: Extending unions and ABI?
    ... typedef struct foo_t { ... Note that I only use pointers to the union in the public api. ... typedef union foobar_t foobar_t; ... because if not I see no advantage in the union compared to using a void pointer together with the individual structs. ...
    (comp.lang.c)
  • Re: Extending unions and ABI?
    ... typedef struct foo_t { ... different types of data (e.g. either a foo or a bar struct) back to the ... Note that I only use pointers to the union in the public api. ... typedef union foobar_t foobar_t; ...
    (comp.lang.c)