unsigned short 유효 범위는?

hermian의 이미지

unsigned short는 0에서 시작하는 것으로 알고 있습니다.
그런데 다음과 같은 코드를 컴파일 하니 gcc에서 warning을 발생하는 군요.

#include <stdio.h>
#include <assert.h>

#define ENSURE(test_)    assert(test_)

int
main(void)
{
    unsigned short int w;

    w=99;

    ENSURE(w >= 0 && w <= 99);


    return 0;
}
/* gcc -Wall -g -o t t.c */
/*
 * Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
 * gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)
 *
 */

컴파일 결과 입니다. (실행파일은 정상 작동합니다. :( )

$gcc -Wall -g -o t t.c
t.c: In function `main':
t.c:13: warning: comparison is always true due to limited range of data type
cinsk의 이미지

w는 unsigned이니, 0 이상인지 아닌지 test하는 것이 불필요하다는 경고입니다.