Essential type model in the MISRA C standard is used to formalize rules and directives. Defining a MISRA-specific model over standard types serves the following purposes:
According to MISRA C, the type of any expression corresponds to an essential type, as outlined in the table:
Essential type category |
Standard types |
---|---|
Boolean essential type |
|
signed essential type |
|
unsigned essential type |
|
real floating essential type |
|
complex floating essential type |
|
character essential type |
|
named enum essential type |
|
For example, an expression with a signed char
, signed int
, or any other signed
type corresponds to a signed essential type.
Look at the following example:
enum FIRST {
f1, f2, f3
};
enum SECOND {
s1, s2, s3
};
int main()
{
enum FIRST lhs = f1;
enum SECOND rhs = s1;
if (lhs == rhs)
return 0;
return 1;
}
The program returns 0
. The variables of the enum
type will be cast to int
and will be equal in the comparison. However, the essential type model of enumeration considers its name. Hence, lhs
and rhs
will have enum<FIRST>
and enum<SECOND>
, respectively. According to MISRA C, comparing enumerations of different types is prohibited. This rule prevents errors and ambiguity.
0