Misra rule 45

6.11 Pointer Type Conversions

Moderators: misra-c, david ward

Locked
meens_india
Posts: 3
Joined: Wed Dec 21, 2005 12:56 pm

Misra rule 45

Post by meens_india » Thu Jan 05, 2006 8:43 am

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

Gavin McCall
Posts: 72
Joined: Mon Sep 13, 2004 9:24 am

Post by Gavin McCall » Thu Jan 05, 2006 9:57 am

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.
Gavin McCall
Personal view only.

meens_india
Posts: 3
Joined: Wed Dec 21, 2005 12:56 pm

Misra rule 45

Post by meens_india » Thu Jan 05, 2006 11:57 am

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));

raveendran
Posts: 3
Joined: Sun Nov 21, 2004 8:19 am

Post by raveendran » Fri Jan 06, 2006 6:18 am

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.
Raveendran Vadakkoot

meens_india
Posts: 3
Joined: Wed Dec 21, 2005 12:56 pm

Misra C rule 45

Post by meens_india » Tue Jan 10, 2006 5:11 am

Hi,

I check out the version from the IAR Misra C reference guide.
It is based on MISRA C 1998.

raveendran
Posts: 3
Joined: Sun Nov 21, 2004 8:19 am

Post by raveendran » Tue Jan 10, 2006 5:24 am

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.
Raveendran Vadakkoot

Locked

Return to “6.11 Pointer Type Conversions”