Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Essential type of integer constant expression of rank greater than unsigned int; interaction with addition to char
#4
The intention of the document is that the following statement in D.1 is just a comment and that it is the result of applying the subsequent sections in Appendix D.
Quote: The essential type of an expression only differs from the standard C type
in expressions where the standard type is either signed int or unsigned int
The MISRA working group agree that various wordings in Appendix D is unclear. This will be clarified in a future TC. In the interim, your examples should be interpreted as follows:


- Is the essential type of 5U unsigned char?
The unsigned type of lowest rank(UTLR) in which 5 fits, which is "unsigned char".

- Is the essential type of 5UL unsigned long?
The C Standard type has a rank greater than int, so the essential type is "unsigned long".

- Is the essential type of 5U*5U unsigned char?
The unsigned type of lowest rank(UTLR) in which 25 fits, which is "unsigned char".

- Is the essential type of 5UL*5UL unsigned char or unsigned long?
The resulting essential type will be "unsigned long", which is the C standard type for the expression.

- Does the essential type of (uint32_t)5U * 5U depend on whether uint32_t is defined as unsigned int or unsigned long if both are 32-bit unsigned integer types?
The C standard type of the expression will be "unsigned int" or "unsigned long" depending on the definition.
If uint32_t is "unsigned int", the essential type will be "unsigned char" as the UTLR is determined by the value of the result which is 25.
If uint32_t is "unsigned long", the C standard type of the expression is "unsigned long" resulting in an essential type of "unsigned long".

- Is the essential type of an expression referring to the value of a bit-field implemented using unsigned long in a C99 compiler that allows this the UTLR for the maximum value of the bitfield, or unsigned long?
The use of unsigned long is implementation defined in C99. The MISRA working group is still considering this.

- Is this sentence in D.1 intended to have any normative effect, and if so what is it and what is its scope?
See discussion at start of the response

- Is the essential type of the expression 'c'+1UL char as stated in D.2, or unsigned long if essential types cannot differ from standard types when the standard type is not signed/unsigned int as noted in D.1?
The intention was that the essential type would be "unsigned long".

- Rule 10.2 Is it intended that "shall have essentially signed type or essentially unsigned type" allows char + long etc.?
The intention was for rule 10.2 not to permit "char + long".
Posted by and on behalf of the MISRA C Working Group


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)