opencv()——uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型、

不念不忘少年蓝@ 2022-05-04 16:28 565阅读 0赞

它就是一个结构的标注,可以理解为type/typedef的缩写,表示它是通过typedef定义的,而不是其它数据类型。

uint8_t,uint16_t,uint32_t等都不是什么新的数据类型,它们只是使用typedef给类型起的别名,新瓶装老酒的把戏。不过,不要小看了typedef,它对于你代码的维护会有很好的作用。比如C中没有bool,于是在一个软件中,一些程序员使用int,一些程序员使用short,会比较混乱,最好就是用一个typedef来定义,如:
typedef char bool;

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

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

附:C99标准中inttypes.h的内容

  1. /*
  2. inttypes.h
  3. Contributors:
  4. Createdby Marek Michalkiewicz <marekm@linux.org.pl>
  5. THISSOFTWARE IS NOT COPYRIGHTED
  6. Thissource code is offered for use in the public domain. You may
  7. use,modify or distribute it freely.
  8. Thiscode is distributed in the hope that it will be useful, but
  9. WITHOUTANY WARRANTY. ALLWARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
  10. DISCLAIMED. This includes but is not limited towarranties of
  11. MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE.
  12. */
  13. #ifndef __INTTYPES_H_
  14. #define __INTTYPES_H_
  15. /* Use [u]intN_t if you need exactly N bits.
  16. XXX- doesn't handle the -mint8 option. */
  17. typedefsigned char int8_t;
  18. typedefunsigned char uint8_t;
  19. typedefint int16_t;
  20. typedefunsigned int uint16_t;
  21. typedeflong int32_t;
  22. typedefunsigned long uint32_t;
  23. typedeflong long int64_t;
  24. typedefunsigned long long uint64_t;
  25. typedefint16_t intptr_t;
  26. typedefuint16_t uintptr_t;
  27. #endif

转自:http://www.cnblogs.com/baochun968/archive/2011/10/19/2218008.html

发表评论

表情:
评论列表 (有 0 条评论,565人围观)

还没有评论,来说两句吧...

相关阅读

    相关 uint16_t

    uint16\_t 是一种数据类型,它表示无符号 16 位整数。这种类型的整数值的范围是 0 到 65535,即最多可以表示 2^16 个不同的数字。uint16\_t 类型的