在Windows中将__int64转换为long [英] Converting __int64 to long in Windows

查看:236
本文介绍了在Windows中将__int64转换为long的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Windows中将__int64转换为long(MSVC8& MSVC6)?





此外,如何将long转换为__int64?如果long是一个负值,它会工作吗?



注意 - 我说的一个场景中__int64变量将总是包含一个值不会更多比32位长。

解决方案

1。 Convert long to __int64



关于 __ int64

_ _int64关键字声明一个新的
类型,一个64位(8字节)整数。由于
具有int,short和long类型,
_ _int64类型具有对应的
无符号版本,因此_ _int64
关键字实际上可用于创建
两种类型。



以下代码示例演示如何
声明两个64位整数,一个
带符号,另一个unsigned: / p>

__ int64 signed_big_int; unsigned __int64 unsigned_big_int;


__ int64 long 。您可以将 long 分配给 __ int64 一个类型转换,当然签名__int64 支持负长整型。



2。 Convert __int64 to long



__ int64 转换为 long ,只有丢失数据的可能性。我的msvc8只警告我数据丢失的可能性。



3。 ::: C99定义了一个名为 int64_t 和未签名版本的标准64位整数类型<$ p
$ b < c $ c> uint64_t 在 stdint.h 。如果要提供可移植代码,应该使用它们,但不要 __int64



注意在C ++编程语言中没有标准的64位整数类型,MSVC使用 __ int64 ,但在linux世界中,你通常使用 int64_t uint64_t C99的 stdint.h 中的$ c> long long unsigned long long 假设您的C ++编译器支持 stdint.h 头文件。


How to convert __int64 to long in Windows (MSVC8 & MSVC6)?

Will a normal typecasting work?

Also, how about converting long to __int64? If the long is a negative value, will it work?

Note - I am talking of a scenario in which the __int64 variable will always contain a value which will not be more than 32 bits long.

解决方案

1. Convert long to __int64

Acorrding to MSDN on the __int64 keyword:

The _ _int64 keyword declares a new type, a 64-bit (8-byte) integer. As with the int, short, and long types, the _ _int64 type has a corresponding unsigned version, so the _ _int64 keyword actually can be used to create two types.

The following code sample shows how to declare two 64-bit integers, one signed and the other unsigned:

__int64 signed_big_int; unsigned __int64 unsigned_big_int;

__int64 is signed,and it should be wider than long.So you could assign long to __int64 without even a type cast and of course the signed __int64 support negative long.

2. Convert __int64 to long

It is OK to convert __int64 to long,only with possibility of loosing data.My msvc8 only warn me of the pssibility of loss of data.

3. Note:

C99 defined a standard 64-bit integer type named int64_t and unsigned version uint64_t in stdint.h.If you want to provide portable code, you should use them but not __int64.

Notice there is no standard 64-bit integer type in C++ programming language,MSVC use __int64,but in linux world you normally use int64_t or uint64_t which is type defined as long long or unsigned long long in C99's stdint.h.Here I assume your C++ compiler support the stdint.h header file.

这篇关于在Windows中将__int64转换为long的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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