嵌入式系统中结构体+冒号+数字的意义
来源:互联网 发布:s3c2440a数据手册 编辑:程序博客网 时间:2024/05/01 14:07
在最近嵌入式开发过程中经常遇到如下结构体形式:
/**@brief GATT Characteristic Properties. */typedef struct{ /* Standard properties */ uint8_t broadcast :1; /**< Broadcasting of the value permitted. */ uint8_t read :1; /**< Reading the value permitted. */ uint8_t write_wo_resp :1; /**< Writing the value with Write Command permitted. */ uint8_t write :1; /**< Writing the value with Write Request permitted. */ uint8_t notify :1; /**< Notications of the value permitted. */ uint8_t indicate :1; /**< Indications of the value permitted. */ uint8_t auth_signed_wr :1; /**< Writing the value with Signed Write Command permitted. */} ble_gatt_char_props_t;/**@brief GATT Characteristic Extended Properties. */typedef struct{ /* Extended properties */ uint8_t reliable_wr :1; /**< Writing the value with Queued Write operations permitted. */ uint8_t wr_aux :1; /**< Writing the Characteristic User Description descriptor permitted. */} ble_gatt_char_ext_props_t;#endif // BLE_GATT_H__
后来发现 这种是位域操作的表示方法,也就是说后面加上“:1”的意思是这个成员的大小占所定义类型的1 bit,
“:2”占2 bit,依次类推。当然大小不能超过所定义类型包含的总bit数。
一个bytes(字节)是8 bit(bit)。例如你的结构中定义的类型是uint8_t,一个字节,共8bit,最大就不能超过8。
其实这样定义是为了节省空间。
例如上面的结构,定义的变量类型是uint8_t,是一字节类型,即8bit。
ble_gatt_char_props_t 总共占了7bit
因此结构的大小如果用sizeof(struct ble_gatt_char_props_t )计算,就是1bytes.(不满一个字节按一个字节算)
0 0
- 嵌入式系统中结构体+冒号+数字的意义
- 结构体中冒号的含义
- 结构体中冒号的作用
- 【记录】Lua中冒号的意义
- 嵌入式系统中volatile 的使用的意义
- 嵌入式系统中volatile 的使用的意义
- C结构体中赋值使用的冒号和点号
- C结构体中赋值使用的冒号和点号
- PHP中双冒号::的用法及意义
- PHP中双冒号::的用法及意义
- 定义结构体时变量名后的冒号和数字
- 定义结构体时变量名后的冒号和数字
- 定义结构体时变量名后的冒号和数字
- 定义结构体时变量名后的冒号和数字
- 定义结构体时变量名后的冒号和数字
- 定义结构体时变量名后的冒号和数字
- 嵌入式系统的结构
- c++中冒号(:)和双冒号(::)的用法和c/c++ 位域结构体
- 5-1 混合类型数据格式化输入 (5分)
- java面试题(二)
- mssql Change Notifications in ASP.NET using SignalR and SqlDependency
- std::function
- OpenStack网络指南(14)DNS集成
- 嵌入式系统中结构体+冒号+数字的意义
- 安装hadoop过程中报的一个错!
- SparkContext源码的简单分析
- 事件分发的源码解析
- Ubuntu Read and Write NetCDF file
- jQuery中的$.getJSON( )方法
- java文件读写实例
- 【软件测试】对比V模型、W模型、H模型,简述他们各自的特点
- 2.FactoryMethod-工厂方法模式