Moderators: misra-c, david ward
- Posts: 11
- Joined: Thu Mar 21, 2013 7:30 pm
- Company: Gentex, Corp.
Within our development group, there has been some discussion as to whether or not the construction
Code: Select all
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?
- Posts: 572
- Joined: Thu Jan 05, 2006 1:11 pm
The essential type rules cover arithmetic types, not pointer types. The second paragraph of 8.10.1 of the MISRA C:2012 guidelines states
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.
In addition, the rule prohibits the use of logical operators ( ! && || ) with pointer operands.
Posted by and on behalf of
the MISRA C Working Group