git/list[1] front-page[2] threads[3] people[4] search[5] about
 

RE: [PATCH] Use unsigned char to squash compiler warnings

From
Randall S. Becker <rsbecker@nexbridge.com>
Date
Mar 4, 2015, 22:34 UTC
Message-ID
<002301d056cb$5d86f5a0$1894e0e0$@nexbridge.com>
In-Reply-To
<xmqqd24o76rh.fsf@gitster.dls.corp.google.com>
Show 19 quoted lines
>On 4 Mar 2015, Junio C Hamano Wrote:
> Sent: March 4, 2015 5:11 PM
> To: Ben Walton
> Cc: git@vger.kernel.org
> Subject: Re: [PATCH] Use unsigned char to squash compiler warnings
> 
> Ben Walton <bdwalton@gmail.com> writes:
> 
> > On Mon, Mar 2, 2015 at 8:30 PM Junio C Hamano <gitster@pobox.com>
> wrote:
> >
> >> The conversion looked good from a cursory view; I didn't check it
> >> very carefully though.
> >>
> > Yes, because of the Solaris ABI, the Studio compiler defaults char to
> > signed char.
> 
> Doesn't our beloved GCC also uses signed char when you write char?
> You keep saying that "defaults to signed char is the problem", but that
does not
Show 17 quoted lines
> explain why those in the rest of the world outside the Solaris land do not
> encounter this problem.
> 
> 	$ cat >x.c <<\EOF
>         #include <stdio.h>
>         int main (void) {
>                 SIGNED char ch = 0xff;
>                 printf("%d\n", ch);
>                 return 0;
>         }
> 	EOF
>         $ gcc -Wall -DSIGNED= x.c && ./a.out
>         -1
>         $ gcc -Wall -DSIGNED=signed x.c && ./a.out
> 	-1
> 
> I think th problem is not Solaris uses signed char for char like everybody
else
> does ;-) but it gives a fairly useless warning to annoy people.
> 
> In any case, here is what I queued, FYI, on bw/kwset-use-unsigned topic.

Even the NonStop c99 compiler does not report a warning - and it is usually very noisy. The default is unsigned char for c99 on this platform, and the value interpretation is significant.

#include <stdio.h>
int main (void) {
        char ch0 = 0xff;
        signed char ch1 = 0xff;
        unsigned char ch = 0xff;
        printf("%d, %d, %d, %d, %d\n", ch0, ch, ch1, ch==ch0, ch==ch1);
        return 0;
}
255, 255, -1, 1, 0
Previous: Junio C Hamano
Message 4 of 4 in “Use unsigned char to squash compiler warnings”
  1. Use unsigned char to squash compiler warningsBen Walton, Mar 2, 2015
  2. Junio C HamanoMar 2, 2015
  3. Junio C HamanoMar 4, 2015
  4. Randall S. BeckerMar 4, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.