日期:2014-05-16  浏览次数:23878 次

警搞comparison is always true due to limited range of data type,如何去除.
编译出现一个警告:
main.c:350: warning: comparison is always true due to limited range of data type

//转义字符
int CharEscap(unsigned char *buf,int iLen)
{
unsigned char temp,endtemp;
int i,j;

for( i = 0 ; i < iLen ; i++)
{
if((buf[i] >= 0x00) && (buf[i] < 0x20)) //0x00-0x20 --这是350行
{
endtemp=buf[iLen++]; //先获取字符串最后一个位置初字符,并把总长+1
for(j=iLen-1;j>i;j--) //空出位置来,来放转义字符
{
temp=buf[j];
buf[j+1]=temp;
}
temp=buf[i]+0x20;
buf[i++]=0x7d;
buf[i]=temp;
buf[iLen]=endtemp;
}
else if(buf[i]==0x7d) //0x7d
{
endtemp=buf[iLen++];
for(j=iLen-1;j>i;j--)
{
temp=buf[j];
buf[j+1]=temp;
}
temp=0x5d;
buf[i++]=0x7d;
buf[i]=temp;
buf[iLen]=endtemp;
}
else if(buf[i]==0x7e) //0x7e
{
endtemp=buf[iLen++];
for(j=iLen-1;j>i;j--)
{
temp=buf[j];
buf[j+1]=temp;
}
temp=0x5e;
buf[i++]=0x7d;
buf[i]=temp;
buf[iLen]=endtemp;

}
return(iLen);
}

应该怎么解决这个警告呢..

------解决方案--------------------
((buf[i] >= 0x00) 永远成立,因为它是无符号的.
可删除