简体   繁体   中英

Why is this code not compliant with MISRA-C 2012 Rule 11.3

I'm having a very hard time understanding why the following code gives me two errors regarding rule 11.3

#define NUM_TASKS 3

typedef struct
{
    void (*TaskFunc)(void);
    uint32_t     Periodicity;
    uint32_t     StartOffset;
} TaskConfig_t;

typedef enum
{
    IDLE,
    RUNNING
} TaskStatus_t;

typedef struct
{
    uint32_t ExecTime;
    uint32_t MinExecTime;
    uint32_t MaxExecTime;
} TaskMetrics_t;

typedef struct
{
    uint32_t TimeToRun;
    uint8_t OverrunCnt;
    TaskStatus_t Status;  
    TaskMetrics_t Metrics;      
} TaskParam_t;

typedef struct
{
  uint32_t *CpuUtilizationPercent;
  uint32_t *Counter;
  TaskParam_t *Params;
  TaskConfig_t *Tasks;
  uint8_t NumTasks;
} PPTS_Config_t;

static uint32_t PPTS_CpuUtilizationPercent;
static uint32_t PPTS_Counter;

static TaskParam_t TaskParams[NUM_TASKS];

static TaskConfig_t TaskConfig[NUM_TASKS];

const PPTS_Config_t CnfPPTS =
{
  &PPTS_CpuUtilizationPercent,
  &PPTS_Counter,
  TaskParams,  /* MISRA-C rule 11.3 violation */
  TaskConfig,   /* MISRA-C rule 11.3 violation */
  NUM_TASKS
};

And in both cases the error is: A cast shall not be performed between a pointer to object type and a pointer to a different object type

The thing here is that both TaskParams and TaskConfig are pointers of the same type that are the struct elements Params and Tasks respectively. I don't understand why I can't assign TaskParams to *Params if they have the exact same type. Am I missign something?

Thank you very much for helping and I hope this could be explained because I'm really frustrated.

EDIT: I've included all the related data types if that helps somehow.

Regards.

MISRA-C 2004 6.10.7 implies that a cast is an explicit type conversion, and gives a bunch of examples in the form of (type)value . This is consistent with the common definition of the term. I believe we can use this definition for the purpose of discussing MISRA-C compliance.

There is no cast being performed anywhere in the posted code. 11.3 says something about casting between different types. I believe 11.3 cannot possibly apply to a situation without a cast, as defined above, being present, no matter what the types involved are.

I conclude that the checker is at fault, and a gross one at that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM