(unsigned)-INT_MIN

O

Old Wolf

I've solved it:

int i= INT_MIN;
unsigned int u= 0U-(unsigned)i;

This has taken too long for something so trivial.

I posted this solution 18 hours ago..

(note that the "0U" makes no difference)
 
V

viza

I posted this solution 18 hours ago..

(note that the "0U" makes no difference)

Yes, but a brain deficit on my part convinced me that the result of unary
negation was signed. :-S
 
K

Keith Thompson

Robbie Hatley said:
Life's not fair. There are never any guarantees of anything,
even if some standard says there are. Live with it.

Example: In C, the latest standard mandates that all compilers
provide data type "long long int". BUT, some compilers don't.
Oh well.

All compilers that conform to the C99 standard provide long long int.
That's not a guarantee; it's a tautology Any compiler that doesn't
provide long long int does not conform to the C99 standard.

No standard can mandate the behavior of implementations that don't
conform to it.
Example: In C++, the latest standard mandates that all compilers
impliment keyword "export" (for exporting templates). But many
(most?) C++ compilers don't. Oh well.

But I think most C and C++ compilers DO have type "long long int",
and I believe that in *ALL* which do, this type has much greater
bit width than type "int".

The C++ doesn't (yet) define long long int, unless I've missed a new
version. But C++ is off-topic here -- and the point is made equally
well just by referring to C.
If you think this is not so, then tell me of a compiler where:

char = 1 bytes
short = 2 bytes
int = 4 bytes
long = 4 bytes
long long = 4 bytes

I doubt anyone is going to bother implimenting "long long" only
to make it the same as "int".

Such an implementation is non-conforming unless CHAR_BIT >= 16.
The standard requires a minimum range for type long long; that
range cannot be satisified unless it's at least 64 bits.

[...]
I tell you what... I'll mail $2 in cash to the first person
who can demonstrate to me a popular C compiler which impliments
"int", "long", and "long long" as all being the same bit width.
I think you can call that a "money back guarantee". :)

I have a C program that prints the characteristics of several C types,
and I've saved the output from the Cray C90, T90, T3E, and SV1. On
all those systems, types int, long, and long long are all 64 bits.
(None of those systems had a C99 compiler, but apparently they all
provided long long as an extension.)

I'm not going to claim your $2, since I wouldn't describe any of those
systems as "popular".
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,167
Latest member
SusanaSwan
Top