论坛: 编程破解 标题: C语言中类型问题[已有结论,谢谢] 复制本贴地址    
作者: kert_t8 [kert_t8]    论坛用户   登录
引用:

类型说明符    数的范围     分配字节数
int       -32768~32767     ■■
short int    -32768~32767     ■■
signed int    -32768~32767     ■■
unsigned int   0~65535        ■■
long int  -2147483648~2147483647  ■■■■
unsigned long  0~4294967295     ■■■■

]

不知道上面的数据是不是正确的,我怎么又听说int应该是 4 bytes,到底是多少啊?是不是跟不同型号的机器有关?在哪里寻找权威的最新的资料?


[此贴被 月之御者(kert_t8) 在 12月21日16时30分 编辑过]

地主 发表时间: 04-12-21 15:07

回复: kert_t8 [kert_t8]   论坛用户   登录
这里又是另外一个版本

[quote]
                Type  Bytes  Bits                Range



            short int    2      16          -32,768 -> +32,767          (32kb)
  unsigned short int    2      16                0 -> +65,535          (64Kb)
        unsigned int    4      32                0 -> +4,294,967,295  ( 4Gb)
                  int    4      32  -2,147,483,648 -> +2,147,483,647  ( 2Gb)
            long int    4      32  -2,147,483,648 -> +2,147,483,647  ( 2Gb)
          signed char    1      8            -128 -> +127
        unsigned char    1      8                0 -> +255
                float    4      32
              double    8      64
          long double  12      96

[quote]

搞不清了

B1层 发表时间: 04-12-21 15:30

回复: kert_t8 [kert_t8]   论坛用户   登录
我的测试结果:
引用:

Size of short int:2
Size of int:4
Size of long int:4
Size of unsigned short int:2
Size of unsigned int:4
Size of float:4
Size of double:8
Size of long double:12



我的测试程序:
引用:


#include <stdio.h>

int main() {
        printf("Size of short int:%d\n",sizeof(short int));
        printf("Size of int:%d\n",sizeof(int));
        printf("Size of long int:%d\n",sizeof(long int));
        printf("Size of unsigned short int:%d\n",sizeof(unsigned short int));
        printf("Size of unsigned int:%d\n",sizeof(unsigned int));
        printf("Size of float:%d\n",sizeof(float));
        printf("Size of double:%d\n",sizeof(double));
        printf("Size of long double:%d\n",sizeof(long double));
}




DELL PC, UNIX环境下 Gcc 编译运行

hope it helps

B2层 发表时间: 04-12-21 16:29

回复: kert_t8 [kert_t8]   论坛用户   登录
而在学校一台叫做 Ohaton 的机器上(不知道是什么机器,只用过没见过,神秘的很),我的运行结果如下:
引用:

Size of short int:2
Size of int:4
Size of long int:4
Size of unsigned short int:2
Size of unsigned int:4
Size of float:4
Size of double:8
Size of long double:16



long double 的长度变了

怀疑是 Sun 的机器,系统是 Solaris。 不知道,猜的

[此贴被 月之御者(kert_t8) 在 12月21日16时45分 编辑过]

B3层 发表时间: 04-12-21 16:44

回复: 286 [unique]   版主   登录
不同编译系统,不同计算机,都不完全一样。

B4层 发表时间: 04-12-21 19:43

回复: kert_t8 [kert_t8]   论坛用户   登录
我知道跟计算机本身有关,但是跟编译器有关系吗?一个Integer的位数不是在计算机里面就已经定义好了吗?

B5层 发表时间: 04-12-22 13:48

论坛: 编程破解

20CN网络安全小组版权所有
Copyright © 2000-2010 20CN Security Group. All Rights Reserved.
论坛程序编写:NetDemon

粤ICP备05087286号