I'm trying to initialize a LARGE_INTEGER
to 0 in a C++ library (C++03 to be exact). Previously, the initialization was:
static LARGE_INTEGER freq = { 0 };
Under MinGW it produced a warning:
missing initializer for member '_LARGE_INTEGER::::HighPart'
So I changed the initialization to the following in accordance with Can a union be initialized in the declaration?:
static LARGE_INTEGER freq = { .QuadPart = 0 };
I'm now testing under Visual Studio 2015, and its producing an error:
81 static LARGE_INTEGER freq = { .QuadPart = 0 };
82 if (freq.QuadPart == 0)
83 {
84 if (!QueryPerformanceFrequency(&freq))
85 throw Exception(Exception::OTHER_ERROR, "Timer: QueryPerformanceFrequency failed ..."));
86 }
hrtimer.cpp(81): error C2059: syntax error: '.'
hrtimer.cpp(81): error C2143: syntax error: missing ';' before '}'
hrtimer.cpp(82): error C2059: syntax error: 'if'
hrtimer.cpp(83): error C2143: syntax error: missing ';' before '{'
hrtimer.cpp(83): error C2447: '{': missing function header (old-style formal list?)
hrtimer.cpp(87): error C2059: syntax error: 'return'
How do I initialize a union to its largest member under the MSVC compiler?
Here is Microsoft's definiton of LARGE_INTEGER
:
#if defined(MIDL_PASS)
typedef struct _LARGE_INTEGER {
#else // MIDL_PASS
typedef union _LARGE_INTEGER {
struct {
DWORD LowPart;
LONG HighPart;
} DUMMYSTRUCTNAME;
struct {
DWORD LowPart;
LONG HighPart;
} u;
#endif //MIDL_PASS
LONGLONG QuadPart;
} LARGE_INTEGER;