代碼:注:應爲 '字符* __restrict__',但說法是 '中int8_t *' 類型的
int8_t ret;
int8_t buf[8];
bytes_written = snprintf(buf, 8, "%" PRId8, 2);
警告:
warning: pointer targets in passing argument 1 of ‘snprintf’ differ in signedness [-Wpointer-sign]
bytes_written = snprintf(buf, 8, "%" PRId8, 2);
^
/usr/include/stdio.h:386:12: note: expected ‘char * __restrict__’ but argument is of type ‘int8_t *’
extern int snprintf (char *__restrict __s, size_t __maxlen,
我知道這可以通過採取buf絕對爲*字符被固定但
是中int8_t的typedef unsigned char型
檢查預處理器輸出,即gcc main.c | grep int8_t
那麼爲什麼編譯器無法理解呢?
使用buf as uint8_t我也得到相同的警告。
編輯:
中int8_t是類型定義爲有符號字符(搞錯了我在原來的職位寫成無符號)
什麼是PRId8。如果對'snprintf'的調用不是'bytes_written = snprintf(buf,8,「%PRId8」,2);'? – Nishant
看看這個http://stackoverflow.com/questions/17744226/int8-t-vs-char-which-is-the-best-one – piyushj
@Nishant不,PRId8是一個CPP宏。 – a3f