typedef 别名
1. 完整例子
| 1 | typedef unsigned int u32; |
| 2 | typedef struct Point { |
| 3 | int x, y; |
| 4 | } Point_t; |
| 5 | |
| 6 | Point_t p = {1, 2}; |
| 7 | u32 mask = 0xFFu; |
2. 好处
- 读代码更短更清晰
- 嵌入式 u8/u16/u32 很常见
- 改底层类型时改一处别名
| 1 | typedef unsigned int u32; |
| 2 | typedef struct Point { |
| 3 | int x, y; |
| 4 | } Point_t; |
| 5 | |
| 6 | Point_t p = {1, 2}; |
| 7 | u32 mask = 0xFFu; |