在win32 Windows操作系统中使用long long数据类型是否安全? [英] Is it safe to use long long data type in a win32 windows OS?

查看:501
本文介绍了在win32 Windows操作系统中使用long long数据类型是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在win32 Windows操作系统中使用long long数据类型是否安全?



我正在为某个应用程序使用sqlite数据库。我注意到INTEGER PRIMARY KEY AUTO INCREMENT数据类型的数据类型是long long(但是在sqlite中是typedefed)。



我也注意到long long数据类型是64位大小。



对于适用于32位操作系统的应用程序使用此数据类型是否真的安全和正确?

Is it safe to use long long data type in a win32 windows OS?

I am using sqlite datatabase for a certain app. I noticed that the INTEGER PRIMARY KEY AUTO INCREMENT data type is of data type long long ( but typedefed in sqlite).

I also noticed that the long long data type is 64 bit in size.

Is it really safe and proper to use this data type for an app that is meant for a 32 bit OS?

推荐答案

是的,它是shure,但检查64位是否始终保留。没有强制转换,也没有签名/取消不匹配。



我会使用自己的typedef数据类型来使其显而易见。



yes it is shure, but check that the 64-bits are at all times preserved. No casts and no signed / unsigend mismatch.

I would use a own typedef datatype to make it obvious.

typedef MY_KEY_TYPE unsigned __int64


原则上,对数据类型大小没有限制,无论操作系统如何,或者不过,CPU。构建程序时,编译器会处理数学运算的方式。如果你有一个32位的cpu,你仍然可以进行64位运算。它只是效率不高。



更好的放置:cpu在设计它的数据类型上效率最高:它具有适当大小和数学运算的寄存器这些寄存器(或多或少)直接。例如,32位系统将执行64位加法,但它将需要多个步骤(高阶和低阶加法并处理任何残留)。定义数据类型时,INT将被定义为目标O / S的本机大小。 SHORT至少为16位,LONG,至少32位等,但INT取决于。 。 !



目前大多数CPU都是64位。匹配的OS类型意味着它将更有效(更快)地运行。



然而,重要的是,在进行任何操作时,你永远不要与其他人混合使用双长注:如果你这样做,就会出现截断错误,这些都是不可恢复的一旦它们应用于您的数据。溢出是另一种可能性。此规则始终适用!不只是双倍长!
In principle, there's no restriction to the datatype size, regardless of the OS, or for that matter, the CPU. When building the program, the compiler handles the way the math is done. If you've a 32-bit cpu, you can still do 64-bit arithmetic. It's just not efficient.

Better put: a cpu is most efficient on the data type for which it is designed: it has registers of the appropriate size and mathematical operations between these registers (more-or-less) directly. A 32 bit system will do, for example, a 64-bit add, but it will take multiple steps (high-order and low order addition and taking care of any "carry over"). When defining data types, INT will be defined as the native size for the targeted O/S. A SHORT is at least 16bit, a LONG, at least 32, etc., but an INT depends . . !

Most current CPU's are 64-bit. A matching OS type means it will run more efficiently (faster).

It is important, however, that you never mix double-long ints with others when doing any operations: if you do, there will be truncation errors and these are irrecoverable once they are applied to your data. Overflows are another possibility. This rule always applies! Not just for double-longs!


这篇关于在win32 Windows操作系统中使用long long数据类型是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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