我想分配字符串到uint8_t
缓冲区在IAR,但我收到一条警告消息。字符串分配到uint8_t在c
rx_buffer.rx_struct.RESP.RESPOND
是struct field
的uint8_t
类型。
我的代码是:
strncpy(rx_buffer.rx_struct.RESP.RESPOND, (uint8_t *)'NS,', 3);
和相关的警告信息如下:
Warning[Pe1422]: multicharacter character literal (potential portability problem)
Warning[Pe167]: argument of type "uint8_t *" is incompatible with parameter of type "char *",
Warning[Pe167]: argument of type "uint8_t *" is incompatible with parameter of type "char const"
我写了一个解决办法:
rx_buffer.rx_struct.RESP.RESPOND[0] = 'N';
rx_buffer.rx_struct.RESP.RESPOND[1] = 'S';
rx_buffer.rx_struct.RESP.RESPOND[2] = ',';
但我不满意它。什么是正确的方法来做到这一点?
使用双引号,使字符串 –