变量声明类型定义 C 中的约定

Variable Declaration typedefs conventions in C

本文关键字:约定 定义 声明 类型 变量      更新时间:2023-10-16

自从我开始用 C 编程以来,我知道/看到每个人都在使用 typedefs 声明变量时使用以下约定,如下所示:

   int32_t *data_value;
   const int16_t *Order_Of_Mag;
   uint16_t min_change;
   uint8_t  eeprom_save_flag;

我知道部分原因是不同架构之间的可移植性。有谁知道何时和/或什么标准规定了这种声明方法?

另外,处理需要使用 char 的标准库 (stdio.h) 函数的推荐方法是什么,因为 char 既不uint8_t也不int8_t(请参阅下面的示例函数)

sscanf(const char *format)
int atio(const char *s)

提前致谢

据我所知,唯一需要你使用这种typedef的标准是项目/公司特定的编码约定。然后,这些编码约定还准确指定要使用的 typedefs(甚至宏),因此可能会UINT32而不是必须使用的uint32_t


至于在charuint8_tint8_t之间进行选择,默认应该是使用char来表示字符数据(即字符串和字符),而uint8_tint8_t用于小数字。