B
Ben Pfaff
Jack Klein said:The result of negating an unsigned integer has a well-defined
result, namely UINT_MAX - value.
UINT_MAX - value + 1
Jack Klein said:The result of negating an unsigned integer has a well-defined
result, namely UINT_MAX - value.
Jack Klein said:[...]kerravon said:The following C program:
int main(void)
{
int x = -2147483648;
return (0);
}
Except C has no negative literals. Your initializer is an expression:
the unary negation operator is applied to a constant. That constant,
2147483648, is indeed so large that it is unsigned (in C90). Negating
this large unsigned number provokes, technically, integer overflow.
No, arithmetic on unsigned types never overflows. The result of
negating an unsigned integer has a well-defined result, namely
UINT_MAX - value.
If that value is outside the range of a signed int and used to
initialize one, the result is implementation-defined.
UINT_MAX - value + 1
James Kuyper said:No - what he said is based upon the implied assumption that LONG_MAX is
2147483647. If LONG_MAX > 2147483647, then the type of 2147483648 could be
long int. If INT_MAX > 2147483647, the type of 2147483648 would be plain
int.
Jack Klein said:No, arithmetic on unsigned types never overflows. The result of
negating an unsigned integer has a well-defined result, namely
UINT_MAX - value.
/* constants used in Solaris */Serve said:I see, so then LLONG_MIN will probably be defined as follows in C99
#define LLONG_MIN (-LLONG_MAX-1LL)
Bartc said:Is it not possible to use a hex constant such as 0x80000000? Would that be
treated as a bit-pattern that includes the sign bit?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.