can't make sense of LARGE_INTEGER struct

前端 未结 2 1577
没有蜡笔的小新
没有蜡笔的小新 2020-12-31 00:29

With C++ and some Winapi things, I encountered this guy:

#if defined(MIDL_PASS)
typedef struct _LARGE_INTEGER {
#else // MIDL_PASS
typedef union _LARGE_INTEG         


        
相关标签:
2条回答
  • 2020-12-31 00:33

    You could directly access the LowPart and HighPart without having to go via the u member. As:

    LARGE_INTEGER x;
    x.HighPart = 42;
    

    (Need to look up though if unnamed structs can be union members in Standard C.)

    0 讨论(0)
  • 2020-12-31 00:36

    Microsoft provides anonymous structs as an extension (their example shows one struct inside another struct, but a struct in a union is similar). If you don't mind non-portable code based on their extension, you can use things like:

    LARGE_INTEGER a;
    a.LowPart = 1;
    

    but if you want portable code, you need:

    a.u.LowPart = 1;
    

    The union lets you use either.

    0 讨论(0)
提交回复
热议问题