|
-
August 3rd, 2010, 10:57 AM
#1
signed to unsigned (and vice versa)
I'm looking for the exact rules according to standard of casting an integer type of signed type to an unsigned integer of the same rank, as well as the contrary (unsigned to signed).
ie:
signed char to unsigned char
unsigned int to signed int
etc...
but not signed char to unsigned int.
In particular, I want to know what happens on machines that do, or don't, use 2's complement. How they behave differently.
Is it safe to write:
Code:
unsigned int max_value = -1;
On any architecture?
The answers I found on the internet were too shady for my tastes.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|