Clarification for underlying type of an integer constant expression - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18) +--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19) +---- Forum: 6.5 Expressions (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=134) +---- Thread: Clarification for underlying type of an integer constant expression (/showthread.php?tid=1336) |
Clarification for underlying type of an integer constant expression - huangcheng_synopsys - 14-04-2017 According to MISRA C++ 2008 section 6.5, the underlying type of an integer contant expression is calculated based on its evaluated value. Griven expressions as below: 1. unsgined long v1 = 1UL; //Underlying type of "1UL" is unsigned char. 2. if(1) {//...} //Underlying type if "1" is signed char. 3. if(2000-1999){//...} //Underlying type of expression "2000-1999" is signed char. Are the undelying type of above expressions correct? Then for the above three cases, there should be implicit cases as following: 1. unsigned char => unsigned long 2. signed char => int 3. signed char => int Correct? Re: Clarification for underlying type of an integer constant expression - misra cpp - 10-07-2017 Yes, your interpretation is correct (but examples 2 and 3 would break other rules - as the controlling expressions are not Boolean expressions) Re: Clarification for underlying type of an integer constant expression - dg1980 - 14-09-2017 Dear MISRA team, is the underlying type of Code: static_cast(1U) a) uint8_t (underlying type of an integer literal in chapter 6)? or b) uint16_t because the static_cast is taken into account (see static_cast(expression) in chapter 6)? If the answer is a) then it would be impossible to make this line of code compliant with rule 5-0-10, right? [code]const uint16_t MASK = 1U Re: Clarification for underlying type of an integer constant expression - misra cpp - 22-09-2017 The answer is b - its uint16_t Se p59 |