W
Wayne Shu
Now I'm reading Stroustrup's The C++ Programming Language(Special
Edition).
In section 4.4 Integer Types, he has wrote that "Using an unsigned
instead of an int to gain one more bit to represent positive integers
is almost never a good idea. Attempts to ensure that some values are
positive by declaring variables unsigned will typically be defeated by
the implicit conversion rules".
I can't understand the two sentences.
The first: "Using an unsigned instead of an int to gain one more bit
to represent positive integers is almost never a good idea."
Why? If int is represented as a two's complement method, it's true
that we can gain one more bit to represent positive integers using an
unsigned.
The second: "Attempts to ensure that some values are positive by
declaring variables unsigned will typically be defeated by the
implicit conversion rules".
In the implicit conversion rules, I think declaring variables signed
also has problems, why he explicit mentioned unsigned, but not signed?
Thanks for explaining it for me.
Regards.
Edition).
In section 4.4 Integer Types, he has wrote that "Using an unsigned
instead of an int to gain one more bit to represent positive integers
is almost never a good idea. Attempts to ensure that some values are
positive by declaring variables unsigned will typically be defeated by
the implicit conversion rules".
I can't understand the two sentences.
The first: "Using an unsigned instead of an int to gain one more bit
to represent positive integers is almost never a good idea."
Why? If int is represented as a two's complement method, it's true
that we can gain one more bit to represent positive integers using an
unsigned.
The second: "Attempts to ensure that some values are positive by
declaring variables unsigned will typically be defeated by the
implicit conversion rules".
In the implicit conversion rules, I think declaring variables signed
also has problems, why he explicit mentioned unsigned, but not signed?
Thanks for explaining it for me.
Regards.