Re: gcc 4 signed vs unsigned char
- From: juanitofoo@xxxxxxxxx
- Date: 27 Jul 2005 23:42:07 -0700
Keith Thompson ha escrito:
> juanitofoo@xxxxxxxxx writes:
> > Old Wolf ha escrito:
> >> juanitofoo@xxxxxxxxx wrote:
> >> > Hello,
> >> > I've just switched to gcc 4 and I came across a bunch of warnings that
> >> > I can't fix. Example:
> >> >
> >> > #include <stdio.h>
> >> >
> >> > int main()
> >> > {
> >> > signed char *p = "Hola";
> >> >
> >> > return 0;
> >> > }
> >> >
> >> > If I compile that file, I get:
> >> > kk.c: In function 'main':
> >> > kk.c:5: warning: pointer targets in initialization differ in signedness
> >> >
> >> > Only if I remove the signed from the declaration it compiles without
> >> > errors. How can I use the signed or unsigned char?
> >>
> >> You should write code that works just as well whether plain char
> >> is signed or not.
> >>
> >> > I'm using gcc 4.0.1. The reason for asking this is because in one
> >> > program I'm always using int8_t and u_int8_t values, and both of them
> >> > are signed or unsigned, no simply 'char' variables.
> >>
> >> You could avoid the warning with:
> >> signed char *p = (signed char *)"Hola";
> >>
> >> However I can't think of a reason why you would prefer this
> >> to:
> >> char const *p = "Hola";
> >>
> >> Can you post some code that demonstrates why you need to
> >> point to non-const, signed chars?
> >
> > The reason is just that I'm using always int8_t instead of char, is
> > that correct and portable for all platforms? (int8_t is a signed char)
>
> Your problem is simple: you're using int8_t instead of char.
>
> The solution is equally simple: use char.
>
> Is there some reason you're using int8_t when char is more appropriate?
I've always thought that using int8_t would be more portable, but it
seems I was wrong. I'll change my code to use char then :) Thanks for
everything.
.
- References:
- gcc 4 signed vs unsigned char
- From: juanitofoo
- Re: gcc 4 signed vs unsigned char
- From: Old Wolf
- Re: gcc 4 signed vs unsigned char
- From: juanitofoo
- Re: gcc 4 signed vs unsigned char
- From: Keith Thompson
- gcc 4 signed vs unsigned char
- Prev by Date: Re: Hints on how to migrate from C++ to C
- Next by Date: question regarding precedence and associativity of ++ and *
- Previous by thread: Re: gcc 4 signed vs unsigned char
- Next by thread: Re: gcc 4 signed vs unsigned char
- Index(es):
Relevant Pages
|
|