MISRA Discussion Forums
Rule 11.2 and example from Exemplar Suite - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.11 Pointer Type Conversions (https://forum.misra.org.uk/forumdisplay.php?fid=38)
+---- Thread: Rule 11.2 and example from Exemplar Suite (/showthread.php?tid=438)



Rule 11.2 and example from Exemplar Suite - pkruk - 08-01-2008

In the mc2_1102.c file there is a following example:

Code:
float32_t float32_1102;
   void *void_ptr = ( void * ) get_int32_ptr ( );
   float32_1102 = ( float32_t ) void_ptr;           /* Not Compliant */

Is the conversion between void pointer and a float type object disallowed by the 11.2 rule?

According to my understanding the rule 11.2 disallows conversions only if we are converting to or from a pointer to object.
float type is clearly not a pointer to object type.
Pointer to void is not a pointer to object type, because void is not an object (it's an incomplete type).

Please correct me if my understanding is not correct.


- George Brown - 09-01-2008

Hi pkruk

Re-writing the rule into a list of positives, I think we get.

Conversions can be performed between a pointer to object and an integral type. But see 11.3 - also requires a cast.

Conversions can be performed between a pointer to object and another pointer to object type. But see 11.4 also requires a cast.

Conversions can be performed between a pointer to object and a pointer to void. Cast not required.

All other conversions are not allowed.

Therefore the following is true.

Conversions shall not be performed between a pointer to any and a float type.

Having said that, is there ever a case when you would want to convert an address to a floating point number? Do remember that not all binary patterns are legal floating point numbers, and (certain) processors can reset on such patterns.

George