Hi,
I'm using TI ARM compiler v5.1.7. And I think that following cases not violates MISRA rules. Or am I missing something?
Luděk Hezina
1. MISRA-C:2004 10.1/R
void a(uint32_t *b);
void c(void);
void a(uint32_t *b)
{
uint32_t e = *b;
*b = e + 1U;
}
void c(void)
{
uint32_t i = 0U;
a(&i); /* violates rule (MISRA-C:2004 10.1/R) The value of an expression of integer type shall not be implicitly converted to a different underlying type if the expression is not constant and is a function argument */
}
This is the same as SDSCM00050007 only different compiler.
2. MISRA-C:2004 12.9/R
double a(void);
double a(void)
{
double diff = 1.0;
diff = -1.0 * diff; /* violates rule (MISRA-C:2004 12.9/R) The unary minus operator shall not be applied to an expression whose underlying type is unsigned */
return diff;
}
Violates rule 12.9 even if uderlying type is double.
3. MISRA-C:2004 17.6/R
typedef struct _sA
{
double b;
}sA;
typedef struct _sB
{
double b;
}sB;
void c(sA *a, sB *b);
void c(sA *a, sB *b)
{
b->b = a->b; /* violates rule (MISRA-C:2004 17.6/R) The address of an object with automatic storage shall not be assigned to another object that may persist after the first object has ceased to exist ("a") */
}
Violates rule 17.6 even if scope of both parameters are equal.
4. MISRA-C:2004 12.2/R
#define ARRAY_LEN 10
typedef struct _sA
{
uint32_t array[ARRAY_LEN];
uint32_t index;
}sA;
void c(sA *a, uint32_t val);
void c(sA *a, uint32_t val)
{
a->array[a->index] = val; /* violates rule (MISRA-C:2004 12.2/R) The value of an expression shall be the same under any order of evaluation that the standard permits */
}
Violates rule 12.2 even if value of an expression if always the same.