Quote:Original post by MaulingMonkey
When you talk about how fast a car can go, you don't say "My Ferrarri can go 10mph" when it can go 160mph (I'm no car expert, so deal with it if that number is off). You say "My Ferrarri can go 160mph", people are probably going to assume that's the maximum speed.
There are any number of cases where you might say "my ferarri can go 10mph" even though it can also go at 160mph.
Let's assume that the minimum maximum speed of any car is 60mph. If somebody asks "what's the maximum speed of a car", which is more accurate: 60mph or 160mph? Obviously the most accurate response wouldn't be either of them, but I think there's a clear conceptual difference between giving an answer which is within the speed ranges of all cars and giving one that is out of the range of some. I think the answer 60mph would somehow be more accurate, because all cars can at least achieve that speed.
Quote:
I'm addressing the point where Nathan Baum states that Vampyre_Dark is somehow more accurate, when Vampyre_Dark made no mention of SCHAR_MIN, SCHAR_MAX, numeric_limits, etc, and left it completely unspecified if this was the full range, minimum standard full range, etc.
You said signed chars have the range -128 to 127. According to the standard, that is a false statement to make. They don't necessarily support all values in that range.
He said signed chars have the range -127 to 127. According to the standard, that is a true statement to make. They necessarily support all values in that range.
Vampyre_Dark obviously
meant the full range, so he
was wrong. But, if one wrote well-formed programs on the basis that the full range of signed chars was -127 to 127, they would be
guaranteed to work on all compliant implementaions. Whilst assuming a range of -128 to 127 wouldn't have the same guarantee.
The range of a signed char is
either [ -127, 127 ]
or [ SCHAR_MIN, SCHAR_MAX ]. No other statement of the range of a signed char is accurate without qualification of which implementation you are referring to.
Quote:
Personally, when someone states a range like that, I take it to mean "this is the full range that ____ can cover". If I were Random N. Ewbie, heard about how overflow usually works, and assumed this, I'd think "So, if I try and assign 128 to a signed char, I'll get -127 right?" - which would be wrong.
If you knew about how overflow worked
according to the standard, you'd know that the behaviour of a
signed type upon receiving a value that is out of range is undefined. The question of whether or not there is bounds checking on signed integer types is left up to the implementation to decide.
This is the whole problem with C/C++ portability. Students are taught that "all the world's an IBM compatible". Instead of being told that the range of a signed char is at least -127 to 127, and more precisely SCHAR_MIN to SCHAR_MAX, they are told it's -128 to 127 and may potentially have to unlearn that if they do some programming for an unusual architecture.