我想分配字符串到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] = ',';
但我不滿意它。什麼是正確的方法來做到這一點?
使用雙引號,使字符串 –