﻿# MISRA Essential Type Model

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:

* increase the strictness of type checking;
* reduce dependence on platform\- and compiler\-specific type implementations;
* establish a basic terminology for describing both explicit and implicit conversions\.

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|\`\_Bool\`|
|\*\*signed \*\*essential type|\`signed char\`<br>\`signed short\`<br>\`signed int\`<br>\`signed long\`<br>\`signed long long\`<br>\`enum \{ \.\.\.\. \};\`|
|\*\*unsigned \*\*essential type|\`unsigned char\`<br>\`unsigned short\`<br>\`unsigned int\`<br>\`unsigned long\`<br>\`unsigned long long\`|
|\*\*real floating \*\*essential type|\`float\`<br>\`double\`<br>\`long double\`|
|\*\*complex floating \*\*essential type|\`\_Complex float\`<br>\`\_Complex double\`<br>\`\_Complex long double\`|
|\*\*character \*\*essential type|\`char\`|
|\*\*named enum\*\* essential type|\`enum <name\> \{ \.\.\.\. \};\`|



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:

```cpp
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\.