14-06-2006, 02:36 PM
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;
}
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;
}
<t>Embedded System</t>