操作 LARGE_INTEGERS

发布于 2024-08-04 08:49:05 字数 511 浏览 9 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

夜深人未静 2024-08-11 08:49:05

LARGE_INTEGER 是一个 64 位整数和一对 32 位整数的并集。如果要对其中之一执行 64 位算术,则需要从联合内部选择 64 位 int。

LARGE_INTEGER a = { 0 };
LARGE_INTEGER b = { 0 };

__int64 c = a.QuadPart - b.QuadPart;

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 a = { 0 };
LARGE_INTEGER b = { 0 };

__int64 c = a.QuadPart - b.QuadPart;
话少心凉 2024-08-11 08:49:05

LARGE_INTEGER 是一个联合,记录在此处。您可能需要一个 QuadPart 成员。

LARGE_INTEGER is a union, documented here. You probably want a QuadPart member.

猫九 2024-08-11 08:49:05

如下:

LARGE_INTEGER x,y;
///
//Some codes...
///

__int64 diff = x.QuadPart - y.QuadPart

因为 QuadPart 被定义为 LONGLONG ,与 __int64 相同。

Here it is:

LARGE_INTEGER x,y;
///
//Some codes...
///

__int64 diff = x.QuadPart - y.QuadPart

Because QuadPart is defined as a LONGLONG , that same as __int64.

巷子口的你 2024-08-11 08:49:05

LARGE_INTEGER 是一个并集,您仍然可以如果您想处理 64 位值,请使用 .QuadPart。

LARGE_INTEGER is a union, you can still use .QuadPart if you want to work on the 64-bit value.

子栖 2024-08-11 08:49:05

正如文档所述在备注部分中:

LARGE_INTEGER结构实际上是一个联合。如果您的编译器内置了对 64 位整数的支持,请使用 QuadPart 成员来存储 64 位整数。否则,使用 LowPart 和 HighPart 成员来存储 64 位整数。

因此,如果您的编译器支持 64 位整数,请使用quadPart,如下所示:

LARGE_INTEGER a, b;
__int64 diff = a.QuadPart - b.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 a, b;
__int64 diff = a.QuadPart - b.QuadPart
栀子花开つ 2024-08-11 08:49:05

除了答案之外,如果您希望构造一个值不为零的 LARGE_INTEGER,则可以分别分配低部分和高部分。 LowPart 是联合中定义的第一个部分,唯一的 highPart 是有符号的。

LARGE_INTEGER li = {0x01234567, -1};

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.

LARGE_INTEGER li = {0x01234567, -1};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文