读书人

ULONG64为啥存放不了8字节的整型

发布时间: 2013-01-06 15:44:47 作者: rapoo

ULONG64为什么存放不了8字节的整型?
本来想做个把ULONG64拆分成高低二个DWORD,结果卡在ULONG64上了
代码如下: sizeof出来8字节。打印出来只有4字节。
写到文件里也一样只有四字节:FFFFFF7F 00000000
print出的结果:
8
2147483647

#include <stdlib.h>
#include <stdio.h>
#include <time.h>

#include <windows.h>

int main(int argc, char **argv) {
HANDLE hFile;
DWORD dwWritten;
unsigned __int64 a = strtol("0xaabbccddeeffaabb", NULL, 0);
printf("%d\n", sizeof(__int64));
printf("%llu\n", a);

hFile = CreateFile( "test",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL );
WriteFile( hFile, &a, 8, &dwWritten, NULL );
CloseHandle(hFile);
return EXIT_SUCCESS;
}

[解决办法]
strtol返回的是32位的long,strtoll才是返回64位的long long,换过来吧。

读书人网 >C语言

热点推荐