Rule 11.3 - Unclear Example 3 - 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.11 Pointer type conversions (https://forum.misra.org.uk/forumdisplay.php?fid=166) +---- Thread: Rule 11.3 - Unclear Example 3 (/showthread.php?tid=1126) |
Rule 11.3 - Unclear Example 3 - thohae - 10-11-2014 The third and last example of Rule 11.3 states that Code: int * const * pcpi; Quote:is non-compliant because the unqualified pointer types are different, namely “pointer to const-qualified int†and “pointer to intâ€But the rule's amplification explicitly states, that Quote:This rule applies to the unqualified types that are pointed to by the pointers.and that the rule's goal is to prevent misalignment. I do not understand why the example is non-compliant, as the cast only adds a const-qualifier and leaves the base type as it is (i.e. "int"). Could you please explain this a little further? Re: Rule 11.3 - Unclear Example 3 - misra-c - 05-12-2014 pcpi is a "pointer" to const qualified object of type "pointer to int" pcpci is a "pointer" to const qualified object of type "pointer to const int" The unqualified object type for pcpi is "pointer to int", which is different to the unqualified object type of pcpci which is "pointer to const int". The phrase "unqualified types" only refers to the top-level const/volatile qualification. See http://www.misra.org.uk/forum/viewtopic.php?t=1293 for further discussions on unqualified pointer types. The rule's rationale applies to more issues than misalignment as mentioned in the second paragraph of the rationale. Such an example could be Code: const int ci = 10; |