Domanda

According to Autosar_SWS the boolean must be unsigned char. But I am having lots of MISRA violation in my compositions, like MISRA rule 10.1 (conversion violation), Rule 12.6 (effective boolean).

I would like to know if I redefine the BOOLEAN for my application like below:

#ifdefine BOOLEAN_T
#undefine BOOLEAN_T

typedef struct {
                 unsigned char TRUE  : 1;
                 unsigned char FALSE : 1;
               } BOOLEAN_T;    

#define TRUE 1;
#define False 0;

#endif

What will be the safety concerns and the consequences?

È stato utile?

Soluzione 3

For safety you can use for example a bit pattern:

unsigned char data = 0x55 << (input_bit & 1);

switch (data):/* instead of if() */
 case 0xaa:
  /*true*/
  break;
 case 0x55:
  /*false*/
  break;
 case default:
  /*exception*/
  break;
}

Altri suggerimenti

If you use a 2 bit struct to represent a single bit quantity, a random bit flip has a 50% chance of changing the true/false value to a value that is neither true nor false.

Please spend some more time studying the C language before attempting to write safety critical software.

By your above method,there is a possibility of MISRA Warnings for using bifields over unsigned char.

I would suggest you to leave the definition of boolean to the platform guys of AUTOSAR (platform types) and concentrate on using boolean as an unsigned char.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top