MISRA Discussion Forums
Rule 18.4, 10.1, and the "type" of pointer to object - 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.18 Pointers and arrays (https://forum.misra.org.uk/forumdisplay.php?fid=173)
+---- Thread: Rule 18.4, 10.1, and the "type" of pointer to object (/showthread.php?tid=1204)



Rule 18.4, 10.1, and the "type" of pointer to object - michael.metivier - 01-10-2015

Within our development group, there has been some discussion as to whether or not the construction
Code:
void test(uint8_t * up)
{
    bool invalid = !up;
    ...
}
is valid with regard to the usage of '!' against a pointer. According to the 18.X rules, '!' is not disallowed for use on pointers, but the explanation of Rule 10.1 with regards to the appropriate essential type for use with '!' would indicate that, as a non-Boolean, its use on pointers should be disallowed.

Do pointers have an "essential type" under the essential type model and what is the correct interpretation in this case?


Re: Rule 18.4, 10.1, and the "type" of pointer to object - misra-c - 09-10-2015

The essential type rules cover arithmetic types, not pointer types. The second paragraph of 8.10.1 of the MISRA C:2012 guidelines states
Quote:The essential type model does this by allocating an essential type to those objects and expressions which ISO C considers to be of arithmetic type.
Rule 10.1 is therefore not applicable to the ! operator when it has a pointer operand.

However, the MISRA-C working group has agreed that this is an omission (which was covered in MISRA-C:2004) and the following words will be added to the amplification to rule 10.1 in a future Technical Corrigendum.
Quote:In addition, the rule prohibits the use of logical operators ( ! && || ) with pointer operands.