N
Nachy
Hi, all.
I got an interesting warning message from my compiler, and before I
complain about a bug I want to make sure what's going on.
I have a method disp_char, meant to append a character to a string,
or a period if the character is a control character. The string better
be the right size (it is, that's not the issue).
int disp_char(int c, char *s)
{
char ch = c & 0xFF; // make sure it's a char
if (ch < 0x20 || ch == 0x7F || ch == 0xFF) // special character?
*s = '.';
else
*s = ch;
*++s = '\0';
return 1;
}
On one system I compiled with, gcc gave me a warning:
$ gcc -o ../dump dump.c
dump.c: In function `disp_char':
dump.c:140: warning: comparison is always false due to limited range
of data type
I separated the comparisons, and gcc seems to be complaining about the
last one (ch == 0xFF).
Am I doing something wrong, or is gcc being paranoid?
BTW, on another system, gcc did not complain at all, even with -Wall.
The program seems to work fine, although I can't seem to generate a
test case with an actual file.
Thanks.
-- Nachy
"Thus, the world wide web must never be assigned the acronym WWW." --
RFC 5513
I got an interesting warning message from my compiler, and before I
complain about a bug I want to make sure what's going on.
I have a method disp_char, meant to append a character to a string,
or a period if the character is a control character. The string better
be the right size (it is, that's not the issue).
int disp_char(int c, char *s)
{
char ch = c & 0xFF; // make sure it's a char
if (ch < 0x20 || ch == 0x7F || ch == 0xFF) // special character?
*s = '.';
else
*s = ch;
*++s = '\0';
return 1;
}
On one system I compiled with, gcc gave me a warning:
$ gcc -o ../dump dump.c
dump.c: In function `disp_char':
dump.c:140: warning: comparison is always false due to limited range
of data type
I separated the comparisons, and gcc seems to be complaining about the
last one (ch == 0xFF).
Am I doing something wrong, or is gcc being paranoid?
BTW, on another system, gcc did not complain at all, even with -Wall.
The program seems to work fine, although I can't seem to generate a
test case with an actual file.
Thanks.
-- Nachy
"Thus, the world wide web must never be assigned the acronym WWW." --
RFC 5513