MISRA Discussion Forums

Full Version: Pointer to void
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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;
}
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);

}
This is compliant. See ISO 6.2.2.3