Just want to know whether the casts in the example below are redundant.
uint16_t basic_units = 4587U;
uint8_t int_val = (uint8_t) (((uint16_t ) (basic_units * 5U)) / 1000U);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
uint8_tcast is redundant. Theuint16_tcast may have the (un)intended consequence of truncating an intermediate value in the calculation ifbasic_units * 5Uwould overflow a normaluint16_tbefore being divided by 1000.