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
__int64keyword:__int64is signed,and it should be wider thanlong.So you could assignlongto__int64without even a type cast and of course thesigned __int64support negative long.2. Convert __int64 to long
It is OK to convert
__int64tolong,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_tand unsigned versionuint64_tinstdint.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 useint64_toruint64_twhich is type defined aslong longorunsigned long longin C99’sstdint.h.Here I assume your C++ compiler support thestdint.hheader file.