473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Promotion and assignment


Take the following:

char unsigned i = 0, j = 5;
...
...
i &= j;

I'd like to see what happens in the last statement. If it were
identical to:

i = i & j;

then the follwoing would happen:
* On the right-hand side, both i and j would be promoted to either
signed int or unsigned int
* The bitwise AND would be performed on these two int's
* Then the result would be converted to an unsigned char to be stored
in i

Does exactly the same thing happen with i &= j?
Jul 9 '08 #1
2 1092
Tomás Ó hÉilidhe wrote:
Take the following:

char unsigned i = 0, j = 5;
...
...
i &= j;

I'd like to see what happens in the last statement. If it were
identical to:

i = i & j;

then the follwoing would happen:
* On the right-hand side, both i and j would be promoted to either
signed int or unsigned int
* The bitwise AND would be performed on these two int's
* Then the result would be converted to an unsigned char to be stored
in i

Does exactly the same thing happen with i &= j?
Yes. 6.5.16.2p3:

"A compound assignment of the form E1 op= E2 differs from
the simple assignment expression E1 = E1 op (E2) only in
that the lvalue E1 is evaluated only once."

.... with special attention to the first "only."

--
Er*********@sun.com
Jul 9 '08 #2
On Jul 9, 4:11 pm, Tomás Ó hÉilidhe <t...@lavabit.comwrote:
Take the following:

char unsigned i = 0, j = 5;
...
...
i &= j;

I'd like to see what happens in the last statement. If it were
identical to:

i = i & j;

then the follwoing would happen:
* On the right-hand side, both i and j would be promoted to either
signed int or unsigned int
Don't you mean int unsigned? :-)
* The bitwise AND would be performed on these two int's
* Then the result would be converted to an unsigned char to be stored
in i

Does exactly the same thing happen with i &= j?
Yes, for the long answer see Mr Sosmans post.
Jul 9 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: BigMan | last post by:
Can someone cite the rules for type promotion in C++? And, in particular, what is the type of the result of adding 2 values of type char?
2
by: Andy | last post by:
Hi... i'm trying to understand the concept of function name overloading in c++. to understand the resolving system it's important to understand the diffrent levels of typecasting (exact match,...
9
by: Fred Ma | last post by:
Hello, I've been trying to clear up a confusion about integer promotions during expression evaluation. I've checked the C FAQ and C++ FAQ (they are different languages, but I was hoping one...
112
by: Carsten Hansen | last post by:
Suppose I'm using an implementation where an int is 16 bits. In the program below, what function is called in the first case, and what is called in the second case? Also, if there is a difference...
16
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. ...
10
by: manochavishal | last post by:
HI, I read that every char in expression is promoted to int. So as function arguments are expressions so type promotion should take place for arguments passed to function. so ***** int...
21
by: Frederick Gotham | last post by:
I set about trying to find a portable way to set the value of UCHAR_MAX. At first, I thought the following would work: #define UCHAR_MAX ~( (unsigned char)0 ) However, it didn't work for me....
6
by: sarathy | last post by:
Hi, What is integer promotion? How is it different from arithmetic conversion? Regards, Sarathy
20
by: David Mathog | last post by:
For this small test program: #include <stdio.h> void main(void){ char buffer="ABCDEFGHIJKLMNOPQRSTUVWXYZ\n"; int size, count; size = 27; /* always a small number which will fit in an int */...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.