LONG和DWORD

来源:互联网 发布:游奇网络有多少人 编辑:程序博客网 时间:2024/06/06 02:28

今天看BITMAP的数据结构说明,发现了DWORD和LONG,还以为LONG要更大一些,原来,对于32位的机子,二者都是32位的,4个字节,只不过LONG有一位被用来做符号位。


typedef   long   LONG; 

typedef   unsigned   long   DWORD;


据说 数据位数和编译器有关。


参看 http://msdn.microsoft.com/en-us/library/aa383751(v=vs.85).aspx


DWORD 是 无符号的2个字。

A 32-bit unsigned integer. The range is 0 through 4294967295 decimal.(2的32次方 减去 1)

This type is declared in WinDef.h as follows:

typedef unsigned long DWORD;


LONG是 有符号的2个字。

A 32-bit signed integer. The range is –2147483648 through 2147483647 decimal.(2的31次方减去1)

This type is declared in WinNT.h as follows:

typedef long LONG;


MFC中的  无符短整型 :  WORD 是无符号的。

WORD

A 16-bit unsigned integer. The range is 0 through 65535 decimal.

This type is declared in WinDef.h as follows:

typedef unsigned short WORD;


INT

A 32-bit signed integer. The range is -2147483648 through 2147483647 decimal.

This type is declared in WinDef.h as follows:

typedef int INT;


我惊讶的发现

很多文章,说int 是16位的http://www.cublog.cn/u2/78880/showart_1894080.html,我开始恍惚了。

经过测试:

root@ubuntu:/home/zhangbin/qt# ./testType
sizeof(int)=4

root@ubuntu:/home/zhangbin/qt# 

我是AMD64上跑的32位系统。

http://tieba.baidu.com/p/1106664400

int  是一个字长。


short int 和int的区别在于,short int 是16位的 ,都是有符号的。

root@ubuntu:/home/zhangbin/qt# ./testType
sizeof(int)=4
sizeof(short int)=2
sizeof(long) = 4

WORD unsigned shot int

DWORD unsigned int

LONG long

INT int


感觉long就是long int ,就是int吧。


参考http://www.cppblog.com/lapcca/archive/2011/04/15/144302.html