Subject: Re: gcc-current and warnings in bin/sh
To: None <tech-userlevel@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-userlevel
Date: 06/05/2002 21:41:39
In article <20020605221820.H2379@snowdrop.l8s.co.uk>,
David Laight <david@l8s.co.uk> wrote:
>On Fri, May 31, 2002 at 07:16:01PM +0100, Ben Harris wrote:
>> In article <GwzK2v.H4E@tac.nyc.ny.us> you write:
>> >In article <E17DpXi-0005ZP-00@chiark.greenend.org.uk>,
>> >Ben Harris <bjh21@netbsd.org> wrote:
>> >>On a system with signed chars, I think UPEOF will end up being just -1.
>
>nope - should be 255
>
>> >>
>> >>In either case, I don't think any of those comparisons is "always true", so
>> >>I'm confused.
>> >
>> >for systems with signed chars this ended up being
>> >
>> >#define UPEOF -129
>> >
>> >which is out of range for char. (it has been fixed)
>> 
>> Ah.  I hadn't noticed the strange dance being done with "base" in the signed
>> case.
>
>Because it isn't! dunno where -129 might come from!

Because on signed character compiles the code goes:

	...
static int base;
	...
	char c;
	...
	c = -1;
        if (c <= 0)
                sign = 1;
        else    
                sign = 0;
        for (nbits = 1 ; ; nbits++) {
                d = (1 << nbits) - 1;
                if (d == c)
                        break;
        }
	...
	base = 1;
        if (sign)
                base += 1 << (nbits - 1);
	...
	if (sign)
		fprintf(hfile, "#define UPEOF ((char)%d)\n\n", -base);
	...


so we have:

	base = 1 << (8 - 1) + 1
	base = 128 + 1

and:
	-base = -129;
and:
	 ((char)-129) = 127;

Now I don't know if 127 is the intended value... But the code does TRT.

christos