Void Pointer Usage

6.11 Pointer Type Conversions

Moderators: misra-c, david ward

Posts: 1
Joined: Tue Jan 09, 2007 10:21 am
Location: United Kingdom

Void Pointer Usage

Post by MikeS » Thu Jan 11, 2007 9:04 am


I have a question regarding the use of Void pointers.

Rule 11.2 is the rule that applies (Conversions shall not be performed between a pointer to object and any type other than an integral type, another pointer to object or a pointer to void).

My first question is:
How do you define \"a pointer to object\"?
By this, do you mean structure, derived types?
I couldn't see any definition for this in the MISRA text.

My second question is:
This rule allows the conversion of a pointer from one type to void. (i.e. to a NULL_PTR to allow for error checking)
I think that this rule also prohibits the use of a defined void ptr, converting this to point to an array or other obect, is this correct?

i.e. the following is illegal:

void *pv_my_void_ptr = NULL_PTR;
u16 *pu16_my_int_ptr = (u16 *)pv_my_void_ptr;

As this would make the checking of alignment (i.e. Rule 11.4) impossible as well as hiding the original type pointed to?

Many Thanks for your consideration.


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

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

1. See for a description of pointers to object types.

2. This is compliant. The rule is to prohibit for example, casting from pointer to object to pointer to function. While compliant, such practice is not without risk.
Posted by and on behalf of
the MISRA C Working Group


Return to “6.11 Pointer Type Conversions”