我遇到了一个与 C 中的类型转换有关的错误。我有一个结构,它保存一个称为 unioffs 的浮点值,我需要将该浮点值放入缓冲区。为此,我正在使用 memcopy 功能。以下是我已经实施的。
typedef struct __attribute__ ((aligned (1), packed))
{
/*01 Bytes*/ uint8_t flags;
/*01 Bytes*/ uint8_t store;
/*04 Bytes*/ float unioffs; /* detector offset in univalues default=0 */
/*04 Bytes*/ float scale; /* detector scale - default =1 */
/*04 Bytes*/ float valalrm; /* value alarm level - in univalue*/
/*04 Bytes*/ float dosalrm; /* dose alarm level - in unidose*/
/*04 Bytes*/ float samperc; /* percentage of the output sampled */
/*04 Bytes*/ float dcstime; /* time of the exposure in seconds */
/*03 Bytes*/ int8_t fillup[3]; /* !!!! allways fill up to 29 bytes */
} DET_STUP;
int main()
{
DET_STUP det_stup[DET_NROFCHAN]; //NROFCHAN is #defined is 10
uint8_t response_to_LV[42];
memset(response_to_LV,0,42);
memset(guc_sensor_config_data,0,40);
//guc_sensor_config_data is a global buffer of 40 bytes
memcpy(guc_sensor_config_data+1*14,(float*)det_stup.unioffs,4);
//Further implementaions to send the buffer through UART
}
我在这里遇到的错误是:error#171: invalid type conversion
我究竟做错了什么?