zoukankan      html  css  js  c++  java
  • C 数据类型 长度

    ----数据类型长度

    C99标准并不规定具体数据类型的长度大小。计算机具有不同位数的处理器,16,32和更高位的64位处理器,在这些不同的平台上,同一种数据类型具有不同的长度。

    char,short,长度相同,分别为1和2个字节。

    int 在32和64位处理器上皆为4个字节,在16位上是2个字节。

    long在16和32位处理器上皆为4个字节,在64位上是8个字节。

    long long 在16和32位处理器上皆为8个字节.

    指针类型的位数与各个处理器的位数相同,分别位16,32,64位。

    为了便于平台的移植,需要确保数据类型长度的一致,引用stdint.h头文件,利用宏定义固定数据类型的长度。

    typedef signed char       int8_t
    typedef short int         int16_t;
    typedef int               int32_t;
    # if __WORDSIZE == 64
    typedef long int          int64_t;
    # else
    __extension__
    typedef long long int     int64_t;

    //unsigned type is the same and omitted here

    ----uintptr_t,intptr_t 

    指针类型的长度与处理器的位数相同,需要对指针进行运算时,利用intptr_t类型,引用stddef.h头文件

    #if __WORDSIZE == 64
    typedef long int                intptr_t;
    #else
    typedef int                     intptr_t;
    #endif
    //unsigned type is the same and omitted here

    ----编程中要尽量使用sizeof来计算数据类型的大小

    ----size_t, ssize_t (in stddef.h)

    Are the types size_t and uintptr_t equivalent?(http://www.viva64.com/en/k/0024/)

    二者数值上相同,同处理器步长。

    --in practice you can consider them equivalent and use them as you like.   

    Usually size_t is used to emphasize we are dealing with a object containing same size,number of elements or iterations;   The type uintptr_t is good for pointers.

  • 相关阅读:
    关于分析web.xml的一篇博客,写的很详细
    (转)Java编译后产生class文件的命名规则
    Standard 1.1.x VM与Standard VM的区别
    throws和throw的用法例子以及检测和非检查异常
    终端IO(上)
    [APUE]进程关系(下)
    [APUE]进程关系(上)
    [APUE]进程控制(下)
    [APUE]进程控制(中)
    深究标准IO的缓存
  • 原文地址:https://www.cnblogs.com/aprilapril/p/4318769.html
Copyright © 2011-2022 走看看