[comp.unix.questions] Tty characters 'undefined' value revisited

dce@mips.UUCP (01/26/87)

A couple of weeks ago, I submitted an article discussing a problem with
the 4.xBSD tty characters (<ttychars.h>, struct ttychars). Basically,
the problem is that the 4.3BSD documentation says that a value of -1
means 'undefined', but our compilers generate unsigned characters.

The general concensus of the responses I got is that the ttychars
structure should be changed so that all of the members are shorts or
ints instead of chars.

Can anyone think of a reason NOT to do this? Are there places where
these values are expected to be chars, and will broken by this change?

-- 
			David Elliott

UUCP: 	{decvax,ucbvax,ihnp4}!decwrl!mips!dce, DDD:  	408-720-1700

wen-king@cit-vlsi.UUCP (02/05/87)

In article <152@quacky.mips.UUCP> dce@quacky.UUCP (David Elliott) writes:
>
>Basically,
>the problem is that the 4.3BSD documentation says that a value of -1
>means 'undefined', but our compilers generate unsigned characters.
>
>The general concensus of the responses I got is that the ttychars
>structure should be changed so that all of the members are shorts or
>ints instead of chars.
>
>Can anyone think of a reason NOT to do this? Are there places where
>these values are expected to be chars, and will broken by this change?

I remember vaguely that you were having problems comparing chars to
the constant -1.  The comparison:

    char c;
    c = -1;
    if(c == -1) ...

tests true on one some but false on others.  That is to be expected
because C does not specify how chars are to be casted to ints.
What you can do is to do the comparison like this:

    char c;
    c = -1;
    if(c == (char) -1) ...

This should test true on all machines.