Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Misra rule 45
#1
Hi,

i compiled the following code using a misra checking compiler

unsigned char data[1];
memset(&data,0x00,sizeof(data));

after compilation it was showing two errors violating rule 45 and rule 77


i changed the line as given below.
memset((void*)&data,0x00,sizeof(data));

it removed the error violating 77.

But i couldnot find any way to comply with rule 45

Can any one have any idea to perform the above actions without
violating the rule
#2
Answer: MISRA C Steering Team 5/1/06

unsigned char data[1];
memset(&data,0x00,sizeof(data));

The example above is not in violation of either Rule 45 or 77.

void * is compatible with any other pointer, and therefore no cast is required.

See 6.2.2.3 in ISO C 9899:1990.

Rule 45 can only be violated by a cast.
#3
Hi,

Iam using IAR embedded workbench compiler
it is a fact any value can be assigned to void*.

But the compiler is showing the violation of rule 45 and rule 77
for the below code

memset(&data,0x00,sizeof(data));
#4
Are you sure that you have to be MISRA C, 1998 compatible? MISRA C, 2002 seem to be so stringent. Thats why Gavin said that whatever you have done is alright.
<t>Raveendran Vadakkoot</t>
#5
Hi,

I check out the version from the IAR Misra C reference guide.
It is based on MISRA C 1998.
#6
You can make the system MISRA C,2002 compliant. As I mentioned earlier, MISRA C, 2002 is NOT very stringent. For things which are not MISRA C compliant, you can release note it mentioning the limitation.
<t>Raveendran Vadakkoot</t>


Forum Jump:


Users browsing this thread: 2 Guest(s)