Re: Unsigned/Signed Mismatch
"Andy Sawyer" <andys@despamme d.com> wrote in message
news:ptkiszvi.f sf@evo6.com...[color=blue]
>
> Remember that char, signed char and unsigned char are three disticnt
> types.[/color]
char is implemented either as signed char or as unsigned char.
FWIW, if I'm using the value in an arithmetic context, then I[color=blue]
> always write either signed char or unsigned char. If I'm using it to
> represent text elements, then I write char. And I probably wouldn't
> write:
>
> char a = 3;
>
> I'd write
>
> char a = '\003';[/color]
It's a personal issue. I am thinking in integral form, so i would write 3 if
i had not a specific character in mind.
[color=blue]
> In fact, unsigned char may be promoted to unsigned int (depending on the
> environment).[/color]
If the involved values fit in int, they get promoted to int. It's in the
standard.
[color=blue]
>[color=green]
> > So in summary, a either signed char either unsigned gets converted to
> > int.[/color]
>
> I had trouble parsing that - I assume you meant
>
> "So in summary, either a signed char or unsigned char gets converted to
> int."
> ?[/color]
"So in summary the variable a, either it is signed char or unsigned char
gets converted to int (in real world scenarios where sizeof(int)>1)" .
--
Ioannis
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.e du ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
"Andy Sawyer" <andys@despamme d.com> wrote in message
news:ptkiszvi.f sf@evo6.com...[color=blue]
>
> Remember that char, signed char and unsigned char are three disticnt
> types.[/color]
char is implemented either as signed char or as unsigned char.
FWIW, if I'm using the value in an arithmetic context, then I[color=blue]
> always write either signed char or unsigned char. If I'm using it to
> represent text elements, then I write char. And I probably wouldn't
> write:
>
> char a = 3;
>
> I'd write
>
> char a = '\003';[/color]
It's a personal issue. I am thinking in integral form, so i would write 3 if
i had not a specific character in mind.
[color=blue]
> In fact, unsigned char may be promoted to unsigned int (depending on the
> environment).[/color]
If the involved values fit in int, they get promoted to int. It's in the
standard.
[color=blue]
>[color=green]
> > So in summary, a either signed char either unsigned gets converted to
> > int.[/color]
>
> I had trouble parsing that - I assume you meant
>
> "So in summary, either a signed char or unsigned char gets converted to
> int."
> ?[/color]
"So in summary the variable a, either it is signed char or unsigned char
gets converted to int (in real world scenarios where sizeof(int)>1)" .
--
Ioannis
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.e du ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Comment