Re: Kill signed chars !!! => PPC uses unsigned chars

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 27, 2005 at 10:21:43PM +0000, J.A. Magallon wrote:
> ... and make gcc4 happy.
> 
> On 05.25, Andrew Morton wrote:
> > 
> > ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.12-rc5/2.6.12-rc5-mm1/
> > 
> > 
> > - Again, if there are patches in here which you think should be merged in
> >   2.6.12, please point them out to me.
> > 
> 
> scripts/ is full of mismatches between char* params an signed char* arguments,
> and viceversa. gcc4 now complaints loud about this. Patch below deletes all
> those 'signed'. Anyways, which was the purpose of declaring 'signed char's
> to store text ?

Well, to my surprize, linux-ppc uses UNSIGNED chars by default. It has amazed
me but it's a fact. Let's compile this little program on tux-ppc :

$ cat ints.c
#include <stdio.h>

main()
{
        int i1, i2;
        char c1, c2;

        c1 = i1 = 0;

        c1--; c2 = c1;
        i1--; i2 = i1;

        c2 &= ~(c2 >> 1);
        i2 &= ~(i2 >> 1);

        if (c1 < 0) printf("c1<0: %d\n", c1); else printf("c1>=0: %d\n",c1);
        if (c2 < 0) printf("c2<0: %d\n", c2); else printf("c2>=0: %d\n",c2);
        if (i1 < 0) printf("i1<0: %d\n", i1); else printf("i1>=0: %d\n",i1);
        if (i2 < 0) printf("i2<0: %d\n", i2); else printf("i2>=0: %d\n",i2);
}

$ gcc-3.3 -v
Reading specs from /usr/lib/gcc-lib/powerpc-linux/3.3.5/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --enable-__cxa_atexit --with-system-zlib --enable-nls --without-included-gettext --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc --disable-multilib powerpc-linux
Thread model: posix
gcc version 3.3.5 (Debian 1:3.3.5-13)

$ gcc-3.3 -O2 -o ints ints.c
ints.c: In function `main':
ints.c:16: warning: comparison is always false due to limited range of data type
ints.c:17: warning: comparison is always false due to limited range of data type

$ ./ints
c1>=0: 255
c2>=0: 128
i1<0: -1
i2>=0: 0

=> As you can see, 0 - 1 returns 255 as a char, and -1 & ~(-1 >> 1) = 128 !
ints are OK BTW. I'm gonna change some of my code to fix this because relying
on signed chars to to detect unassigned values (-1) is wrong !

Oh and BTW, here's the result on x86 :

$ gcc-3.3 -o ints ints.c
$ ./ints
c1<0: -1
c2>=0: 0
i1<0: -1
i2>=0: 0

Cheers,
Willy

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux