Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MISRA C:2012 Rule 10.8 Question
#1
The rule 10.8 states that "The value of a composite expression shall not be cast to a different essential type category or a wider essential type".

I understand that casting to a wider type will cause incompatibilities for different compilers where int have different width, but I don't understand why we cannot cast it to a different essential type category with the same or less width. 

In other words, the example

Code:
(uint32_t)(int32_t+int32_t)  /* Non-compliant */

is non-compliant, but the rationale behind this is feels unclear to me, as this code does not have inconsistency between compilers.

A possible explanation is that:
(1) despite the fact that writing like this will guarantee consistent behavior across compilers and architectures, 
(2) it easily misleads an inexperienced human programmer to interpret the computation inside the "()" to be carried out in uint32_t, which is of course not the case,
so this is banned.

I want to know whether this human readability is the rational behind the first clause of the rule. Thanks for looking into this matter in advance!
Reply


Messages In This Thread
MISRA C:2012 Rule 10.8 Question - by elfdream - 11-11-2023, 03:29 PM
RE: MISRA C:2012 Rule 10.8 Question - by misra-c - 08-08-2024, 03:37 PM
RE: MISRA C:2012 Rule 10.8 Question - by elfdream - 09-08-2024, 02:14 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)