Pointer to void

6.11 Pointer Type Conversions

Moderators: misra-c, david ward

Locked
fwamolina
Posts: 8
Joined: Tue May 30, 2006 1:42 pm
Location: Argentine

Pointer to void

Post by fwamolina » Wed Jun 14, 2006 3: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;
}
Embedded System

fwamolina
Posts: 8
Joined: Tue May 30, 2006 1:42 pm
Location: Argentine

also have other case

Post by fwamolina » Thu Jun 15, 2006 1:38 pm

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);

}
Embedded System

misra-c
Posts: 566
Joined: Thu Jan 05, 2006 1:11 pm

Post by misra-c » Wed May 09, 2007 4:43 pm

This is compliant. See ISO 6.2.2.3
---
Posted by and on behalf of
the MISRA C Working Group

Locked

Return to “6.11 Pointer Type Conversions”