Walter Roberson a écrit :
I haven't had a chance to look at anything C99 might have
added with respect to rounding modes and what-not, but as far as
C89 is concerned, operations on variables are defined as being
operations on *values*, not operations on representations.
I read that sentence several times and I can still not quite parse
it.
In my opinion there are no values in a machine, just representations
in some bits. What actually exists are those bits.
The software implicitely assigns those representations a value.
For instance you assign to 3+Volts the value "1" and to
0.3V the value "0".
Then you group those bits in groups of (say) 32 of them and
you say that the bits are to be understood from right to left
as 1, 2, 4, 8, 16, 32, 64, etc up to 2**31. And you give
the name to that bunch of bits "unsigned int".
Nowhere is any "value". In the machine there are only bits,
and they can be interpreted by the software in many different
ways to give different values.
You can abstract from those representations and speak about "operations
on values", meaning that no matter how "345" is represented and no
matter how "10" is represented, 345+10 MUST give 355.
OK.
But this apparent abstraction breaks down immediately when we see that
in a 16 bit implementation 30 000 + 10 000 gives a negative number.
This breakdown has been incorporated into the language and everybody
agrees that it is the only nomal behavior. The standard claims this
is "undefined behavior" and stops there.
If the representation (internal structure) used on a particular system
happens to implement the C value semantics efficiently, then Good, but if
not then it is up to the implementation to add whatever internal code
it needs so that the C value semantics are preserved, not whatever
semantics happen to be convenient for the internal representation.
Obvious. But what you are saying is just that the implementation must
agree with the standard, what is possible in most machines since C
maps efficientely in most machines.
And so what?
We were speaking of operator overloading and I indicated that it is
well adapted for numeric types, and that other applications like
"abc"+"cde" --> "abccde" are wrong, since it violates some of the basic
rulmes of addition: a + b == b + a. That's why I said that. Not so
explicitely but that was my intention. In c++ this doesn't hold.