ULARGE_INTEGER 联合的意义何在? [英] What is the point of the ULARGE_INTEGER union?

查看:30
本文介绍了ULARGE_INTEGER 联合的意义何在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://msdn.microsoft.com/en-us/library/windows/desktop/aa383742%28v=vs.85%29.aspx

它们应该是这样使用的,在 LowPart 和 HighPart 上设置两个 32 位值,然后在 QuadPart 上执行算术运算.

They are supposed to be used like this, set two 32 bit values on LowPart and HighPart and then perform arithmetic on the QuadPart.

int a,b,c;
ULARGE_INTEGER u;
...
u.LowPart = a;
u.HighPart = b;
u.QuadPart += c;

因此,如果您打算在 QuadPart(64 位)上执行算术运算,那么您需要一个 64 位处理器,对吗?那么重点是什么?为什么不直接给 QuadPart 赋值?

So if you are going to perform arithmetic on the QuadPart(64 bits) anyways you need a 64 bit processor, right? So what is the whole point? Why not assign the value directly to the QuadPart?

推荐答案

您不需要 64 位处理器来对 64 位数据类型执行算术运算.我所知道的所有 32 位编译器都支持 64 位整数的算术运算.如果硬件不允许本地算术,那么编译器必须生成代码来执行算术.通常,这将使用编译器 RTL 中的支持函数.

You don't need a 64 bit processor to perform arithmetic on a 64 bit data type. All 32 bit compilers that I know of support arithmetic on 64 bit integers. If the hardware doesn't allow native arithmetic, then the compiler has to generate code to do the arithmetic. Typically this will make use of support functions in the compiler's RTL.

该结构旨在供不提供对 64 位数据类型的本机支持的编译器使用.您链接到的文档清楚地说明了这一点:

The struct is intended for use by compilers that don't provide native support for 64 bit data types. The very documentation to which you linked makes that clear:

注意您的 C 编译器可能本身就支持 64 位整数.为了例如,Microsoft Visual C++ 支持 __int64 大小的整数类型.有关详细信息,请参阅 C 随附的文档编译器.

Note Your C compiler may support 64-bit integers natively. For example, Microsoft Visual C++ supports the __int64 sized integer type. For more information, see the documentation included with your C compiler.

不支持本机 64 位整数的编译器将无法将 QUADPART 联合成员视为整数.

Compilers that don't support native 64 bit integers will not be able to treat the QUADPART union member as an integer.

typedef union _ULARGE_INTEGER {
  struct {
    DWORD LowPart;
    DWORD HighPart;
  };
  struct {
    DWORD LowPart;
    DWORD HighPart;
  } u;
  ULONGLONG QuadPart;
} ULARGE_INTEGER, *PULARGE_INTEGER;

以及ULONGLONG的定义:

#if !defined(_M_IX86)
 typedef unsigned __int64 ULONGLONG;
#else
 typedef double ULONGLONG;
#endif

当然,过去 10 年(或更久)编写的所有编译器都将原生支持 64 位整数.但是这个联合最初是在很久以前引入的,那时编译器的情况会有所不同.查看 Windows 头文件时,请始终牢记历史和遗留问题.

Of course, all compilers written in the past 10 years (or more) will have native support for 64 bit integers. But this union was originally introduced a very long time ago and the compiler landscape would have been different then. When looking at Windows header files, always bear in mind the history and legacy.

这篇关于ULARGE_INTEGER 联合的意义何在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆