Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
10.3 Clarify if narrower in the title refers the the rank of the essential type
#1
The rule 10.3 says:
Quote:The value of an expression shall not be assigned to an object with a narrower //essential type//

What does it mean to be narrower? To have a lower rank, or to have a smaller size?

For instance, on a platform where 
Code:
sizeof(long) == sizeof(long long)

Is the following code compliant with rule 10.3:
Code:
long l = 0;
long long ll = 0;
l = ll; // Compliant or not?

My feeling is that it is compliant, because the word rank is not used here, while it is explicitly used in other parts of the rule, but I'm not 100% confident.
Reply
#2
Clause 5.10.2 note 4 (before Rule 10.1) defines Wider and Narrower

"4. When comparing two types of the same type category, the terms wider and narrower are used to describe their relative sizes as measured in bytes. Two different types are sometimes implemented with the same size."

If sizeof(long) == sizeof(long long) then l is not narrower than ll, so it is compliant with R.10.3

However, if the size of long long subsequently changes (eg for a different target or compiler), then it would become non-compliant.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)