Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the UTLR of -1?
#1
I'm attempting to determine the essential type of the following expression:

Code:
(unsigned short)1 - (unsigned short)2

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:
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?
Reply


Messages In This Thread
What is the UTLR of -1? - by Loïc - 09-06-2026, 09:36 AM
RE: What is the UTLR of -1? - by misra-c - 08-10-2026, 12:15 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)