操作 LARGE_INTEGERS
我正在 win32 下的 MS dev studio 中将一些代码从 C 转换为 C++。在旧代码中,我使用 QueryPerformanceCounter() 进行一些高速计时,并对获得的 __int64 值进行了一些操作,特别是减号和除法。但现在在 C++ 下我被迫使用 LARGE_INTEGER 因为这就是 QueryPerformanceCounter() 返回的结果。但现在,在我尝试对值进行一些简单数学运算的行上,我收到错误:
error C2676: binary '-' : 'LARGE_INTEGER' does not Define this operand or a conversion to a type Accepted to the pre-dedicated Operators
I attempts将变量转换为 __int64 但随后得到:
error C2440: 'typecast' :无法从 'LARGE_INTEGER' 转换为 '__int64'
如何解决此问题?
谢谢,
I am converting some code from C to C++ in MS dev studio under win32. In the old code I was doing some high speed timings using QueryPerformanceCounter() and did a few manipulations on the __int64 values obtained, in particular a minus and a divide. But now under C++ I am forced to use LARGE_INTEGER because that's what QueryPerformanceCounter() returns. But now on the lines where I try and do some simple maths on the values I get an error:
error C2676: binary '-' : 'LARGE_INTEGER' does not define this operator or a conversion to a type acceptable to the predefined operator
I tried to cast the variables to __int64 but then get:
error C2440: 'type cast' : cannot convert from 'LARGE_INTEGER' to '__int64'
How do I resolve this?
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
LARGE_INTEGER 是一个 64 位整数和一对 32 位整数的并集。如果要对其中之一执行 64 位算术,则需要从联合内部选择 64 位 int。
LARGE_INTEGER is a union of a 64-bit integer and a pair of 32-bit integers. If you want to perform 64-bit arithmetic on one you need to select the 64-bit int from inside the union.
LARGE_INTEGER
是一个联合,记录在此处。您可能需要一个QuadPart
成员。LARGE_INTEGER
is a union, documented here. You probably want aQuadPart
member.如下:
因为 QuadPart 被定义为 LONGLONG ,与 __int64 相同。
Here it is:
Because QuadPart is defined as a LONGLONG , that same as __int64.
LARGE_INTEGER 是一个并集,您仍然可以如果您想处理 64 位值,请使用 .QuadPart。
LARGE_INTEGER is a union, you can still use .QuadPart if you want to work on the 64-bit value.
正如文档所述在备注部分中:
LARGE_INTEGER
结构实际上是一个联合。如果您的编译器内置了对 64 位整数的支持,请使用 QuadPart 成员来存储 64 位整数。否则,使用 LowPart 和 HighPart 成员来存储 64 位整数。因此,如果您的编译器支持 64 位整数,请使用quadPart,如下所示:
As the Documentation says in the Remarks section :
The
LARGE_INTEGER
structure is actually a union. If your compiler has built-in support for 64-bit integers, use the QuadPart member to store the 64-bit integer. Otherwise, use the LowPart and HighPart members to store the 64-bit integer.So if your compiler supports 64 bit integers use quadPart like this :
除了答案之外,如果您希望构造一个值不为零的 LARGE_INTEGER,则可以分别分配低部分和高部分。 LowPart 是联合中定义的第一个部分,唯一的 highPart 是有符号的。
In addition to the answers, if you are looking to construct a LARGE_INTEGER with a value other than zero, you can assign the low and high parts separately. LowPart is first as defined in the union, and the only highPart is signed.