Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clarification for underlying type of an integer constant expression
#1
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?
<t></t>
Reply
#2
Yes, your interpretation is correct (but examples 2 and 3 would break other rules - as the controlling expressions are not Boolean expressions)
Posted by and on behalf of
the MISRA C++ Working Group
Reply
#3
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
<t></t>
Reply
#4
The answer is b - its uint16_t Se p59
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)