Pointer 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: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17) +---- Forum: 6.11 Pointer Type Conversions (https://forum.misra.org.uk/forumdisplay.php?fid=38) +---- Thread: Pointer to void (/showthread.php?tid=272) |
Pointer to void - fwamolina - 14-06-2006 I just want to know when a cast shall be performed between a pointer to void and any type or vice versa? for example is this code compliance with misra-c? void* GetNewObject (void); void SetProperty (void*, uint8_t); void main (void) { void* lpVoid; OBJECT_T* lpObject; lpVoid = NULL; lpObject = NULL; lpObject = GetNewObject (); /* there is an explicit cast in this function from OBJECT_T* type to void* type, so GetNewObject return an OBJECT_T* qualifier type */ lpVoid = lpObject; SetProperty (lpVoid, 4U); lpObject = lpVoid; if (lpObject == lpVoid) { SetProperty (lpObject, 5U); } lpVoid = lpObject; } also have other case - fwamolina - 15-06-2006 void UseObject (lpVoid*); void main (void) { OBJECT01_T* lpObject01; OBJECT02_T* lpObject02; void* lpVoid; lpVoid = lpObject01; UseObject (lpVoid); /* lpVoid is a void* type here or a OBJECT01_T* type? */ lpVoid = lpObject02; UseObject (lpVoid); } - misra-c - 09-05-2007 This is compliant. See ISO 6.2.2.3 |