The answer seems obvious, but considering this MISRA rule
Rule 11.5 A conversion should not be performed from pointer to void into pointer to object
would it not be safer to have memory allocation functions like "malloc" return a pointer to a char* instead? This type of pointer has no alignment issues.
Thanks.
Well, MISRA is not in a position to overturn decisions made by the ISO standard committee about the C programming language, some 25 years ago.
But that's irrelevant anyway, because you're overlooking MISRA 2004 Rule 20.4, which forbids any use of malloc() & friends.
MISRA or not - dynamic memory isn't a great idea in embedded devices with long uptimes. Too much problems with fragmented heap, resulting in failed memory allocations even if there are lots of free memory.
Thanks folks.
View all questions in Keil forum