c - Accessing enum value in memcpy
问题描述
I am trying to copy the value of enum to some array through memcpy. Before this i will be doing a state change of enum from 0 to 1. Then i am copying this enum value to my array. I observed that there is state change but the value is not copied into array. Initial enum value is 0 i.e., INIT_STATE, then i change the value to DISASSOCIATE_STATE.
My array is data[9], where 0-7 bytes is the device_id and 8 is the tag_state. State is when BLE communication happens between tag and mobile app, i give 1 in the custom characteristics from nRF connect app, the state should change to DISASSOCIATE. This is happening that i can check in switch case.
So, When that changes, i should update the state in array. For that i'm using memcpy.
memcpy should update the tag state i.e., 8th byte of data[9].
My enum is
typedef enum {
INIT_STATE,
DISASSOCIATE_STATE,
ASSOCIATE_STATE,
SET_CONFIG_STATE
}cmd_type;
This is defined in one file. I am accessing it using cmd_type state; This is the memcpy command I'm using,
memcpy(data[8],state+1, 1);
Why the value is not getting copied?
解决方案
推荐阅读
- python - 如何使用 matplotlib 从时间序列数据中绘制条形图?
- neural-network - 神经网络中误差函数导数公式的简化
- r - 如何根据两个变量对数据进行子集化
- python - Pycharm,Selenium 进程以退出代码零完成
- neo4j - Neo4j 查询到表问题
- asp.net-mvc - TextAreaFor 和 EditorFor 边框是不同的阴影
- html - 如何使用 flexbox 创建问题/答案列?
- python - 如何从矩阵中获取值到数据框
- python - Python 除法返回不正确的结果
- reactjs - 如何在 Material-ui 4、React 16.8、TypeScript 3.5 中使用 Refs