C语言中基本的数据类型

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

stdint.h源码:

 1 /* Created by hwli <1163765781@qq.com> */
 2 #ifndef _STDINT_H
 3 #define _STDINT_H
 4 
 5 // Define C99 equivalent types.
 6 typedef signed char          int8_t;
 7 typedef signed short         int16_t;
 8 typedef signed int           int32_t;
 9 typedef signed long long     int64_t;
10 
11 typedef unsigned char        uint8_t;
12 typedef unsigned short       uint16_t;
13 typedef unsigned int         uint32_t;
14 typedef unsigned long long   uint64_t;
15 
16 typedef unsigned char        byte;
17 typedef unsigned short       word;
18 typedef unsigned int         dword;
19 typedef unsigned long long   qword;
20 
21 typedef enum 
22 {
23     FALSE = 0,
24     TRUE  = 1,
25 } bool26 
27 #define INT8_MIN (-128) 
28 #define INT16_MIN (-32768)
29 #define INT32_MIN (-2147483647 - 1)
30 #define INT64_MIN  (-9223372036854775807LL - 1)
31 
32 #define INT8_MAX 127
33 #define INT16_MAX 32767
34 #define INT32_MAX 2147483647
35 #define INT64_MAX 9223372036854775807LL
36 
37 #define UINT8_MAX 0xff /* 255U */
38 #define UINT16_MAX 0xffff /* 65535U */
39 #define UINT32_MAX 0xffffffff  /* 4294967295U */
40 #define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
41 
42 #endif  //_STDINT_H
原文地址:https://www.cnblogs.com/hwli/p/9254375.html