-
Misra Rule 11.2
Hi
I am not sure if many of you are aware of what the Misra C 2004 standards are but rule 11.2 states
Rule 11.2 (required) Conversions shall not be performed between a pointer to object and any other than an integral type, another pointer to object type or a pointer to void.
I am looking for opinions of what you think this actually means!
for example this would be a violation
Code:
float *x;
long y;
x=&y; /*Violation*/
however would the below code be a violation?
Code:
long *x;
int y;
x=&y; /*Violation*/
It produces a compiler warning using Dev C++ but the Misra rule seems to state that it is ok to convert between integral types.
I hope I have been clear enough!
-
depends on the size of int and long -- if they are both the same size it would be ok, but not if they are different sizes. If a long = 4 bytes and an int = 2 bytes, then dereferencing the long pointer would produce unpredictible results. The safest way to do it is to declare the pointer the same data type as the object to which it points -- the pointer should be int* in your example.