MISRA Discussion Forums

Full Version: Misra rule 45
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.
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));
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.
Hi,

I check out the version from the IAR Misra C reference guide.
It is based on MISRA C 1998.
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.