Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pointer to void
#1
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;
}
<t>Embedded System</t>
#2
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);

}
<t>Embedded System</t>
#3
This is compliant. See ISO 6.2.2.3
Posted by and on behalf of the MISRA C Working Group


Forum Jump:


Users browsing this thread: 1 Guest(s)