Rule 11.3

Moderators: misra-c, david ward

Post Reply
schileboh
Posts: 1
Joined: Wed Jan 29, 2014 1:47 pm
Company: Guillebeau Engineering GmbH

Rule 11.3

Post by schileboh » Fri Jan 31, 2014 9:47 am

hello guys

i've a problem. i'm not sure if the following code is compliant to the Rule 11.3:

Code: Select all

typedef struct SomeHeaderType
{
   uint8_t type;
   uint32_t timestamp;
   uint16_t some_attribute;
}SomeHeaderType;

void foo(uint8_t *buffer_ptr)
{
   SomeHeaderType *headerPtr = (SomeHeaderType*)buffer_ptr;
   if(headerPtr->type == 3)
   {
      uint16_t attribute = headerPtr->some_attribute;
      ...
   }
   ...
}
is it allowed to cast a 8-bit buffer pointer to a struct pointer? from my point of view, this code is not compliant, but i have some code examples here that do this and the code suggests to be MISRA conform...

thanks for clarification.

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

Re: Rule 11.3

Post by misra-c » Thu Feb 20, 2014 8:46 am

You are correct in saying that the cast from "pointer to unsigned 8-bit" to "pointer to struct" is not compliant with rule 11.3.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.11 Pointer type conversions”