Re: Quick check on signed promotion of bytes
- From: santosh <santosh.k83@xxxxxxxxx>
- Date: Thu, 31 Jan 2008 23:53:24 +0530
vippstar@xxxxxxxxx wrote:
On Jan 31, 6:22 pm, Eric Sosman <Eric.Sos...@xxxxxxx> wrote:
t...@xxxxxxxxxxx wrote:Ah, I apologise, just something i am not sure about, char unsigned x,
I have a byte called "x". I want byte "y" to be the complement of
"x" (i.e. all the bits flipped).
Initially I wrote:
char unsigned x, y;
...
x = 72;
y = ~x;
But then I thought that the following might happen on your average
system (CHAR_BIT == 8, sizeof(int) == 4):
1) x is promoted to signed int.
2) The complement is take of this signed int.
3) This signed int is then converted to an unsigned char
That's right, under your assumptions. On "exotic" machines
where UCHAR_MAX > INT_MAX (for example, on hardware where all
of char, short, and int are 16 bits wide), then x promotes to
an unsigned int instead of to an int in step 1.
Also see vippstar's response: It's wrong.
y; means unsigned char x, 'plain' char y?
No, it's equivalent to:
unsigned char x;
unsigned char y;
.
- References:
- Quick check on signed promotion of bytes
- From: toe
- Re: Quick check on signed promotion of bytes
- From: Eric Sosman
- Re: Quick check on signed promotion of bytes
- From: vippstar
- Quick check on signed promotion of bytes
- Prev by Date: Re: Quick check on signed promotion of bytes
- Next by Date: Re: declaration of variable in for loop
- Previous by thread: Re: Quick check on signed promotion of bytes
- Next by thread: Re: Quick check on signed promotion of bytes
- Index(es):
Relevant Pages
|