The L suffix causes the literal 1000 to be evaluated as a long, which, if I understand type promotion correctly, should then promote the command to a long as well, avoiding rollover. You can, if desired, also use the suffix UL to force a literal to an unsigned long.
Yes but the you assign the result to i which is a 16 bit signed int so you still get 14646(or so). i needs to be long. Try running the program (after some sleep).
Yes but the you assign the result to i which is a 16 bit signed int so you still get 14646(or so).
The post title says "Concatenation of operations yields wrong results". It mentions nothing about assigning a value to a variable.
Adding the L to the constant (and removing the useless cast) WILL result in the correct result. That the now correct result is assigned to a variable of the wrong size/type is a separate problem.
But, yeah, I did miss the point you were trying to make, I guess.
But i is not long and you can't promote the LHS of the assignment in that way. The = trunicates the value from the RHS to fit in the 16 bit int of the LHS.
holmes4:
But i is not long and you can't promote the LHS of the assignment in that way. The = trunicates the value from the RHS to fit in the 16 bit int of the LHS.
Try running the program I DID!.
Mark
Read the code. That's why I bothered to quote it. It says
long i;
The int is in
i=((int)command)*1000;
Everything on the RHS is type int. The LHS is declared long.
Do you have some form of dyslexia? If not then slow down, code is not jokes from reader's digest.