MISRA Discussion Forums

Full Version: Rule 18.4, 10.1, and the "type" of pointer to object
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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.