MISRA Discussion Forums
Rule 11.3 - 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.11 Pointer type conversions (https://forum.misra.org.uk/forumdisplay.php?fid=166)
+---- Thread: Rule 11.3 (/showthread.php?tid=1024)



Rule 11.3 - schileboh - 31-01-2014

hello guys

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

Code:
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.


Re: Rule 11.3 - misra-c - 20-02-2014

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.