zoukankan      html  css  js  c++  java
  • uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型

    uint8_t / uint16_t / uint32_t /uint64_t  是什么数据类型


    在nesc的代码中,你会看到非常多你不认识的数据类型,比方uint8_t等。咋一看。好像是个新的数据类型,只是C语言(nesc是C的扩展)里面好像没有这种数据类型啊!怎么又是u又是_t的?非常多人有这种疑问。论坛上就有人问:以*_t结尾的类型是不是都是long型的?在baidu上查一下,才找到答案,这时才发觉原来自己对C掌握的太少。

    那么_t的意思究竟表示什么?详细的官方答案没有找到,只是我认为有个答案比較接近。它就是一个结构的标注。能够理解为type/typedef的缩写,表示它是通过typedef定义的,而不是其他数据类型。

    uint8_t,uint16_t。uint32_t等都不是什么新的数据类型。它们仅仅是使用typedef给类型起的别名。新瓶装老酒的把戏。

    只是,不要小看了typedef,它对于你代码的维护会有非常好的作用。

    比方C中没有bool,于是在一个软件中。一些程序猿使用int,一些程序猿使用short,会比較混乱。最好就是用一个typedef来定义,如:
    typedef char bool;

    一般来说,一个C的project中一定要做一些这方面的工作,由于你会涉及到跨平台。不同的平台会有不同的字长。所以利用预编译和typedef能够让你最有效的维护你的代码。为了用户的方便。C99标准的C语言硬件为我们定义了这些类型,我们放心使用就能够了。

     依照posix标准,一般整形相应的*_t类型为:
    1字节     uint8_t
    2字节     uint16_t
    4字节     uint32_t
    8字节     uint64_t

    附:C99标准中inttypes.h的内容
    00001 /*
    00002    inttypes.h
    00003 
    00004    Contributors:
    00005      Createdby Marek Michalkiewicz <marekm@linux.org.pl>
    00006 
    00007    THISSOFTWARE IS NOT COPYRIGHTED
    00008 
    00009    Thissource code is offered for use in the public domain.  You may
    00010    use,modify or distribute it freely.
    00011 
    00012    Thiscode is distributed in the hope that it will be useful, but
    00013    WITHOUTANY WARRANTY.  ALLWARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
    00014    DISCLAIMED.  This includes but is not limited towarranties of
    00015    MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE.
    00016  */
    00017 
    00018 #ifndef __INTTYPES_H_
    00019 #define __INTTYPES_H_
    00020 
    00021 /* Use [u]intN_t if you need exactly N bits.
    00022    XXX- doesn't handle the -mint8 option.  */
    00023 
    00024 typedefsigned char int8_t;
    00025 typedefunsigned char uint8_t;
    00026 
    00027 typedefint int16_t;
    00028 typedefunsigned int uint16_t;
    00029 
    00030 typedeflong int32_t;
    00031 typedefunsigned long uint32_t;
    00032 
    00033 typedeflong long int64_t;
    00034 typedefunsigned long long uint64_t;
    00035 
    00036 typedefint16_t intptr_t;
    00037 typedefuint16_t uintptr_t;
    00038 
    00039 #endif

  • 相关阅读:
    webpack devServer配置项的坑
    app混合开发 fastlick.js 在ios上 input标签点击 不灵敏 处理
    vue 学习八 自定义指令
    Verilog数值大小比较
    Verilog实现Matlab的fliplr函数
    基本不等式
    如何读取ila数据
    Xilinx FPGA时钟IP核注意事项
    FPGA Turbo译码器注意事项
    EbN0转SNR
  • 原文地址:https://www.cnblogs.com/claireyuancy/p/6789533.html
Copyright © 2011-2022 走看看