Be Careful When Using Bit Field
Below illustration is based on MSP430, IAR. See the implementation below.
typedef struct
{
uint8_t groupAddress :; //group address
uint8_t pointAddress :; //point address
uint8_t deviceType :; //device type;
}DeviceAddressS; gDeviceAddress.groupAddress = address >> ;
gDeviceAddress.pointAddress = address & 0x7;
Let’s check the assemble code, there are total 26 execution codes and 28 execution codes for two lines C source code.
If we don’t use the bit field, what will be happened?
typedef struct
{
uint8_t pointAddress; //point address
uint8_t groupAddress; //group address
uint8_t deviceType; //device type;
}DeviceAddressS;
gDeviceAddress.groupAddress = address >> ;
gDeviceAddress.pointAddress = (address & 0x7);
Checking the assemble code again, there are total 10 execution codes and 12 execution codes.
So, the rule is that “be careful when using bit field”. Do you really has no enough space? In fact, if you don’t have enough space, the MCU performance is low, so don’t use bit field normally. If you real want to use it, using union and assigning whole value at the same time, see example below.
typedef union
{
uint8_t value;
struct
{
uint8_t pointAddress :; //point address
uint8_t groupAddress :; //group address
}bitFields;
}AddressU; void AddressTest(void)
{
uint8_t adddress = ;
AddressU temp;
temp.value = adddress;
temp.value |= (adddress & 0x7);
}
It has a good performance.
Note that, they have same performance when reading for bit field or non-bit field.
Be Careful When Using Bit Field的更多相关文章
- Sample Credential Providers
Windows Vista Sample Credential Providers Overview Contents Terms of Use Release Notes SampleCre ...
- How to reduce Index size on disk?减少ES索引大小的一些小手段
ES索引文件瘦身总结如下: 原始数据:(1)学习splunk,原始data存big string(2)原始文件还可以再度压缩倒排索引:(1)去掉不必要的倒排索引信息:例如文件位置倒排._source和 ...
- salesforce 零基础学习(六十二)获取sObject中类型为Picklist的field values(含record type)
本篇引用以下三个链接: http://www.tgerm.com/2012/01/recordtype-specific-picklist-values.html?m=1 https://github ...
- salesforce 零基础学习(五十八)通过sObject的field返回其对应的基础类型
项目中有时候会要求通过sObject的Field的type类型返回其对应的基本类型,然后对其进行相关的处理,创建sObject的field可以选择的type类型是固定多的. 上述类型可以转换成几种基本 ...
- SharePoint 2013 Create taxonomy field
创建taxonomy field之前我们首先来学习一下如果创建termSet,原因是我们所创建的taxonomy field需要关联到termSet. 简单介绍一下Taxonomy Term Stor ...
- 代码的坏味道(7)——临时字段(Temporary Field)
坏味道--临时字段(Temporary Field) 特征 临时字段的值只在特定环境下有意义,离开这个环境,它们就什么也不是了. 问题原因 有时你会看到这样的对象:其内某个实例变量仅为某种特定情况而设 ...
- 【转】Django Model field reference学习总结
Django Model field reference学习总结(一) 本文档包含所有字段选项(field options)的内部细节和Django已经提供的field types. Field 选项 ...
- go-使用 unsafe 修改 struct 中的 field 的值
以下是方法,不要纠结原理,等东西积累多了,你才有能力纠结原理: 首先,你需要有一个这样的函数,这是在 nsq 的源码里直接抄过来的: func unsafeValueOf(val reflect.Va ...
- MongoDB查询转对象是出错Element '_id' does not match any field or property of class
MongoDB查询转对象是出错Element '_id' does not match any field or property of class 解决方法: 1.在实体类加:[BsonIgno ...
随机推荐
- netcore 2.0 部署 到iis
.net Core2.0应用程序发布window服务器报错容易错过的配置. 1.应用程序发布. 2.IIS上新建网站. 3.应用程序池选择无托管代码. 4.服务器上安装DotNetCore.1.0.2 ...
- IDEA中安装ibatis插件
若想在IDEA中使数据库的相关配置能够快速链接即Ctrl+单击跳转,则安装插件 效果如图,跳转成功
- 更改centos源为aliyun
完全参考 http://mirrors.aliyun.com/help/centos?spm=5176.bbsr150321.0.0.d6ykiD 1.备份 mv /etc/yum.repos.d/C ...
- ios中字典转模型的创建以及简单用法
// appModel.h // Created by zzqqrr on 17/8/19. // #import <Foundation/Foundation.h> @interface ...
- Python中读取文件中的json串,并将其写入到Excel表格中
Json:JavaScript Objective Notation,是一种轻量级的数据交换格式.Json最广泛的应用是作为AJAX中web服务器和客户端的通讯的数据格式.现在也常用语http请求中, ...
- Java学习笔记31(IO:Properties类)
Properties类,表示一个持久的j集,可以存在流中,或者从流中加载 是Hashtable的子类 map集合的方法都能用 用途之一:在开发项目中,我们最后交给客户的是一个编译过的class文件,客 ...
- 1.带宽&吞吐量
1.带宽 网络带宽是指在一个固定的时间内(1秒),能通过的最大位数据.就好象高速公路的车道一样,带宽越大,好比车道越多 带宽是一个非常有用的概念,在网络通信中的地位十分重要.带宽的实际 ...
- deconvolution layer parameter setting
reference: 1. Paper describes initializing the deconv layer with bilinear filter coefficients and tr ...
- 20165228 2017-2018-2 《Java程序设计》第9周学习总结
20165228 2017-2018-2 <Java程序设计>第9周学习总结 教材学习内容总结 URL类是java.net包中的一个重要的类,URL的实例封装着一个统一资源定位符(Unif ...
- 11.2.0.4rac service_name参数修改
环境介绍 )客户环境11. 两节点 rac,集群重启后,集群资源一切正常,应用cs架构,连接数据库报错,提示连接对象不存在 )分析报错原因,连接数据库方式:ip:Port/service_name方式 ...