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

From: Willy Tarreau (willy_at_w.ods.org)
Date: 06/21/05

  • Next message: Pierre Ossman: "Re: [PATCH] Pointer cast warnings in scripts/"
    Date:	Tue, 21 Jun 2005 14:54:04 +0200
    To: "J.A. Magallon" <jamagallon@able.es>
    
    

    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 majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Pierre Ossman: "Re: [PATCH] Pointer cast warnings in scripts/"

    Relevant Pages

    • Re: Getting rid of int
      ... You seem to be confusing bit with byte throughout this message. ... that is a professional C programmer that is "confused" about ints. ... Because it is rare that the exact number of bits/bytes in the data type ...
      (comp.programming)
    • Re: [Linux-NTFS-Dev] [2.6-GIT] NTFS: Release 2.1.25.
      ... BTW, ntfsmount in almost all truncating cases leave absolutely clean ... but windows driver itself often ... >> BTW, great work, but IMHO to early for mainline. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: Howto read line from a stream
      ... Let alone representations ... abstract data type. ... of ints, additive because, composed of ints, etc). ... common knowledge is used to implement protocols, ...
      (comp.lang.ada)
    • Re: Worrisome IDE PIO transfers...
      ... The thieves... ... they've stolen my precioussss. ... BTW: You don't need the km_types voodoo as the conversion routine is ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)
    • Re: [2.4 PATCH] bugfix: ARP respond on all devices
      ... This can be of interest to others BTW: ... ip arp append table input deny ... to put under Documentation/networking/arp.txt so solve most common problems. ... send the line "unsubscribe linux-kernel" in ...
      (Linux-Kernel)