MISRA Discussion Forums
10.3 Clarify if narrower in the title refers the the rank of the essential type - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.10 The essential type model (https://forum.misra.org.uk/forumdisplay.php?fid=165)
+---- Thread: 10.3 Clarify if narrower in the title refers the the rank of the essential type (/showthread.php?tid=1773)



10.3 Clarify if narrower in the title refers the the rank of the essential type - Loïc - 25-06-2026

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.


RE: 10.3 Clarify if narrower in the title refers the the rank of the essential type - misra-c - 08-10-2026

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.