我遇到了一個警告,我不太明白。這個警告是通過比較我認爲是一個無符號和另一個無符號的符號而產生的。瞭解警告「比較提升〜無符號與無符號」
這裏是源:
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
int main()
{
uint8_t *arr = malloc(8);
assert(arr);
/* fill arr[] with stuff */
if (arr[3] != (uint8_t)(~arr[2])) { // Warning is here
/* stuff */
}
return EXIT_SUCCESS;
}
我所要建造採用以下步驟:
[email protected]:~ $ gcc -o test -Wall -Wextra test.c
test.c: In function ‘main’:
test.c:13:16: warning: comparison of promoted ~unsigned with unsigned [-Wsign-compare]
我使用gcc版本4.7.2 20121109(紅帽4.7.2-8)
如何解決上述問題?
這實際上似乎是一個錯誤http://gcc.gnu.org/bugzilla/show_bug.cgi?id = 38341 – Kotte