09-06-2026, 09:36 AM
I'm attempting to determine the essential type of the following expression:
This is a operation subject to arithmetic conversion (D.7.9), both operands are essentially unsigned, and the expression is an integer constant expression, so according to item 4.1, the essential type of the result is the UTLR of the result.
However, the result is a signed integer with the value -1. The following program demonstrates this:
So we have to compute the UTLR of a negative value, which is not defined.
Is there an error in my reasoning, or is this a limitation in the essential type system?
Code:
(unsigned short)1 - (unsigned short)2This is a operation subject to arithmetic conversion (D.7.9), both operands are essentially unsigned, and the expression is an integer constant expression, so according to item 4.1, the essential type of the result is the UTLR of the result.
However, the result is a signed integer with the value -1. The following program demonstrates this:
Code:
#include <stdio.h>
#define TYPE(x) _Generic((x), \
int: printf("int\n"), \
unsigned int: printf("unsigned int\n"), \
default: printf("other\n") \
)
int main() {
TYPE(1u - 2u);
TYPE(1 - 2);
TYPE((unsigned short)1 - (unsigned short)2);
}So we have to compute the UTLR of a negative value, which is not defined.
Is there an error in my reasoning, or is this a limitation in the essential type system?

