Thread: Misra Rule 11.2

  1. #1
    Registered User
    Join Date
    Apr 2006

    Misra Rule 11.2


    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
    float *x;
    long y;
    x=&y; /*Violation*/
    however would the below code be a violation?

    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!
    Last edited by hammer1234; 04-06-2006 at 06:05 AM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. Big help in Astar search code...
    By alvifarooq in forum C++ Programming
    Replies: 6
    Last Post: 09-24-2004, 11:38 AM
  3. Rule of 72
    By sonict in forum C++ Programming
    Replies: 12
    Last Post: 01-23-2003, 08:31 PM
  4. Who should rule the world?
    By CoderBob in forum A Brief History of
    Replies: 7
    Last Post: 02-07-2002, 07:01 AM