此代码在使用 Visual Studio 2010 编译时
#include <cstdlib>
#include <cstdio>
int numbers[] = { 23, 24, 25, 25, 28, 20, 20 };
int main(void) {
int d = -1, x=0;
size_t count = sizeof(numbers) / sizeof(numbers[0]);
if (d <= (sizeof(numbers) / sizeof(numbers[0]))-2)
x = numbers[d+1];
if (d <= count-2)
x = numbers[d+1];
}
给我一个有符号/无符号不匹配警告 onif (d <= count-2)
但不是 on if (d <= (sizeof(numbers) / sizeof(numbers[0]))-2)
。为什么是这样?我已启用所有警告。