lilburne said:
Do you want a control whose width is 4294967295?
I don't understand what you are implying. (Perhaps
that -1 is a large value when converted to unsigned).
I also don't understand why such a large number.
For example, if a short int holds 16 bits, and the
control width is a short unsigned int, then I am allowed
to have a with that is 65535. Which is fine.
Just explain to me what a control looks like that
has a width of -3 and a height of -10.
How about one that is 4294967295 breaths per second?
I believe you are assuming 32 bits per integer.
Let us assume 8 bits per integer. Then you are claiming
"How about 255 breaths per second." But what does this
have to do with signed or unsigned?
You comment doesn't have any place in either section.
Functions that use integral numbers should have range
checking. For example, one could state that the upper
limit is 50 breaths per second. Using an 8-bit signed
integer allows a range of -128 to +127. So if the
function for calculating breath rates uses a signed
8-bit integer, then a negative value is possible.
Using unsigned integers, a negative value would be
rejected (providing there is no automatic conversion)
by the compiler. One cannot have -5 breaths per second.
If I use a signed value for breaths per second then I
would have to use an addition lower bound check to make
sure that a value less than zero was not passed. One
could have zero breaths per second (such as when the
the machine is disconnected). Again, how can one
have a negative breath per second or a breath per
negative second?
My point is that when a range is in the domain of positive
integral values, one should use an unsigned data type.
When the range is allowed to go into the domain of negative
and positive integral values, one should use a signed
data type. One never counts negative chickens or apples.
However, an index in a decrementing loop may be decremented
past zero, depending on whether zero is a valid index and
when the decrementing takes place.
--
Thomas Matthews
C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq:
http://www.parashift.com/c++-faq-lite
C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book