![]() |
11.5: Conversion from point to void - 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: 11.5: Conversion from point to void (/showthread.php?tid=1068) |
11.5: Conversion from point to void - michael.metivier - 17-06-2014 According to the Exception to 11.3, it is permissible to convert a pointer to object into pointer to char, signed char, or unsigned char. There doesn't appear to be an Example within the MISRA document, but I believe it would look like Code: uint8_t *p8; Code: uint16_t *p16; Given that the MISRA rules, themselves, allow conversion of pointer to object into both pointer to void and pointer to character, and that the spec indicates that pointer to void and pointer to character can not have conflicting alignment requirements, should it be allowed to convert from pointer to void to pointer to character: Code: void *p; Re: 11.5: Conversion from point to void - misra-c - 25-06-2014 The exception to rule 11.3 exists because conversion from a "pointer to object" to a "pointer to character" type is a commonly used programming idiom for accessing the underlying byte data of the object. There is no such compelling requirement for conversions from other types such as "pointer to void" and so no exception has been made in that case. The conversion from void* to another pointer type requires a deviation as no type information is included. This includes conversions from void* to char*. Re: 11.5: Conversion from point to void - michael.metivier - 25-06-2014 For functions which take arbitrary data and operate on it in a byte-wise fashion, for example, calculating a CRC, which would be the preferred method according to the MISRA guidelines: Code: uint32_t CRC(size_t length, void * data); Code: uint32_t CRC(size_t length, uint8_t * data); Re: 11.5: Conversion from point to void - misra-c - 26-06-2014 The MISRA Working group can not make a comment on a preferred style of programming. The exception to 11.3 only refers to casts, since rule 11.3 only applies to casts. Implicit conversions from pointer to object type to pointers to character type are constraint errors( C90 6.3.16.1, C99 6.5.16.1). |