Subject: Assming char == signed char?
To: None <firstname.lastname@example.org>
From: None <email@example.com>
Date: 06/19/1995 13:13:00
Andrew Cagney writes:
> Has the NetBSD source files ever been built on a machine where `char' is
> really `unsigned char'?
Yes, us ;-) (NetBSD/arm??). This has in fact been the cause of a few problems,
but as we fix them we're noting them down for correction in the independent
> I have the feeling that it it hasn't been. I
> ask because I've stumbled across code of the form:
> if (tty->a_member_of_type_char == -1)
The most common example of a char (in our case unsigned) being compared with
a signed value is during argument processing, ie:
while((c = getopt(argc, argv, "BNRWb:ers:w")) != -1)
We're generally changing the declaration of c from char to int (since
getopt() returns an int...
> which, if char is unsigned, is a little pointless :-) (this was in the
> kernel, exactly where is at home :-( ).
We're collecting them up... Apparently lots of these signed char assumptions
were cleared out a while ago. There were none (or *very* few) found in the
kernel source, but they're quite common in the program sources.
Any chance of telling us where your example came from ;-)
> As an aside is the correct fix:
> (signed char)tty->a_member_of_type_char == -1
> tty->a_member_of_type_char == (char)(-1)
Er. Open to debate I think. We tend to fix them on a case by case basis,
choosing the neatest fix appropriate.
Scott Stevens <firstname.lastname@example.org> Tel: 0171 594 6943 or x46943
Analyst/Programmer, Cluster Support, Computer Centre, Imperial College
The other diners didn't take much notice, even when Death leaned back and lit a
rather fine pipe. Someone with smoke curling out of their eye sockets takes
some ignoring, but everyone managed it. - Mort, Terry Pratchett