uint8_t / uint16_t / uint32_t /uint64_t 是什么数据类型c++/c? (在andriod源码中)

时间:2022-09-06 11:57:20
typedef signed char int8_t
typedef unsigned char uint8_t
typedef signed int int16_t
typedef unsigned int uint16_t
typedef signed long int int32_t
typedef unsigned long int uint32_t
typedef signed long long int int64_t
typedef unsigned long long int uint64_t


这个就是uint8_t / uint16_t / uint32_t /uint64_t 定义
c工程跨平台时用这样定义避免出错。




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




Linux man page
Name
<stdint.h>: Standard Integer Types -


Detailed Description
#include <stdint.h>
Use [u]intN_t if you need exactly N bits.
Since these typedefs are mandated by the C99 standard, they are preferred over rolling your own typedefs.


Exact-width integer types


Integer types having exactly the specified width
typedef signed char int8_t
typedef unsigned char uint8_t
typedef signed int int16_t
typedef unsigned int uint16_t
typedef signed long int int32_t
typedef unsigned long int uint32_t
typedef signed long long int int64_t
typedef unsigned long long int uint64_t
Integer types capable of holding object pointers


These allow you to declare variables of the same size as a pointer.
typedef int16_t intptr_t
typedef uint16_t uintptr_t
Minimum-width integer types


Integer types having at least the specified width
typedef int8_t int_least8_t
typedef uint8_t uint_least8_t
typedef int16_t int_least16_t
typedef uint16_t uint_least16_t
typedef int32_t int_least32_t
typedef uint32_t uint_least32_t
typedef int64_t int_least64_t
typedef uint64_t uint_least64_t
Fastest minimum-width integer types


Integer types being usually fastest having at least the specified width
typedef int8_t int_fast8_t
typedef uint8_t uint_fast8_t
typedef int16_t int_fast16_t
typedef uint16_t uint_fast16_t
typedef int32_t int_fast32_t
typedef uint32_t uint_fast32_t
typedef int64_t int_fast64_t
typedef uint64_t uint_fast64_t
Greatest-width integer types


Types designating integer data capable of representing any value of any integer type in the corresponding signed or unsigned category
typedef int64_t intmax_t
typedef uint64_t uintmax_t
Limits of specified-width integer types


C++ implementations should define these macros only when __STDC_LIMIT_MACROS is defined before <stdint.h> is included
#define INT8_MAX 0x7f
#define INT8_MIN (-INT8_MAX - 1)
#define UINT8_MAX (__CONCAT(INT8_MAX, U) * 2U + 1U)
#define INT16_MAX 0x7fff
#define INT16_MIN (-INT16_MAX - 1)
#define UINT16_MAX (__CONCAT(INT16_MAX, U) * 2U + 1U)
#define INT32_MAX 0x7fffffffL
#define INT32_MIN (-INT32_MAX - 1L)
#define UINT32_MAX (__CONCAT(INT32_MAX, U) * 2UL + 1UL)
#define INT64_MAX 0x7fffffffffffffffLL
#define INT64_MIN (-INT64_MAX - 1LL)
#define UINT64_MAX (__CONCAT(INT64_MAX, U) * 2ULL + 1ULL)
Limits of minimum-width integer types


#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST8_MIN INT8_MIN
#define UINT_LEAST8_MAX UINT8_MAX
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST16_MIN INT16_MIN
#define UINT_LEAST16_MAX UINT16_MAX
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST32_MIN INT32_MIN
#define UINT_LEAST32_MAX UINT32_MAX
#define INT_LEAST64_MAX INT64_MAX
#define INT_LEAST64_MIN INT64_MIN
#define UINT_LEAST64_MAX UINT64_MAX
Limits of fastest minimum-width integer types


#define INT_FAST8_MAX INT8_MAX
#define INT_FAST8_MIN INT8_MIN
#define UINT_FAST8_MAX UINT8_MAX
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST16_MIN INT16_MIN
#define UINT_FAST16_MAX UINT16_MAX
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST32_MIN INT32_MIN
#define UINT_FAST32_MAX UINT32_MAX
#define INT_FAST64_MAX INT64_MAX
#define INT_FAST64_MIN INT64_MIN
#define UINT_FAST64_MAX UINT64_MAX
Limits of integer types capable of holding object pointers


#define INTPTR_MAX INT16_MAX
#define INTPTR_MIN INT16_MIN
#define UINTPTR_MAX UINT16_MAX
Limits of greatest-width integer types


#define INTMAX_MAX INT64_MAX
#define INTMAX_MIN INT64_MIN
#define UINTMAX_MAX UINT64_MAX
Limits of other integer types


C++ implementations should define these macros only when __STDC_LIMIT_MACROS is defined before <stdint.h> is included
#define PTRDIFF_MAX INT16_MAX
#define PTRDIFF_MIN INT16_MIN
#define SIG_ATOMIC_MAX INT8_MAX
#define SIG_ATOMIC_MIN INT8_MIN
#define SIZE_MAX (__CONCAT(INT16_MAX, U))
Macros for integer constants


C++ implementations should define these macros only when __STDC_CONSTANT_MACROS is defined before <stdint.h> is included.
These definitions are valid for integer constants without suffix and for macros defined as integer constant without suffix


#define INT8_C(value) ((int8_t) value)
#define UINT8_C(value) ((uint8_t) __CONCAT(value, U))
#define INT16_C(value) value
#define UINT16_C(value) __CONCAT(value, U)
#define INT32_C(value) __CONCAT(value, L)
#define UINT32_C(value) __CONCAT(value, UL)
#define INT64_C(value) __CONCAT(value, LL)
#define UINT64_C(value) __CONCAT(value, ULL)
#define INTMAX_C(value) __CONCAT(value, LL)
#define UINTMAX_C(value) __CONCAT(value, ULL)
Define Documentation