Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Void Pointer Usage

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.

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

Forum Jump:

Users browsing this thread: 1 Guest(s)