Conversions outside of the essential type categories

Moderators: misra-c, david ward

Post Reply
gdavis
Posts: 3
Joined: Tue Oct 05, 2010 11:48 pm
Company: Green Hills Software

Conversions outside of the essential type categories

Post by gdavis » Wed Jul 11, 2018 12:26 am

Hello,

With respect to the essential type rules, do conversions to types that are outside the essential type categories count as violations of the rules? For example:

Code: Select all

#include <stdint.h>
char buf[80];
char *p = buf;
uintptr_t p_plus_one;
void foo(void);
void foo(void) {
    // This next statement violates R11.4.  But does
    // it violate R10.8?  As a pointer type, p+1 does not
    // have a clear essential type category.
    p_plus_one = (uintptr_t)(p+1);
}
On the one hand, the spirit of the rule seems like it should prohibit such things. On the other hand, TC1 amends rule 10.1 to describe how a pointer type may not be used as an operand of a logical operator.

Thank you for your time.

-Greg

misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Re: Conversions outside of the essential type categories

Post by misra-c » Thu Oct 18, 2018 2:29 pm

Rules 10.2-10.8 only apply to expressions whose operands have arithmetic types. This will be clarified in a future release.
Therefore rule 10.8 does not apply to "(uintptr_t)(p+1)".

However p+1 violates rule 18.4 and (uintptr_t)(p+1) violates rule 11.4
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.10 The essential type model”