Martin said:
As far as I can see, it is implementation-defined whether or not `~0'
produces a trap representation on a one's complement implementation.
If it doesn't, it is unspecified if it produces a negative or normal
zero.
Let me make sure that I follow your reasoning/concern here
On a ones-complement machine, A ones-complement negative zero may be a trap
representation. On such a machine, ~0 may also represent a trap value, as it
would be binary identical to an ones-complement negative zero.
Before the `&' operator is evaluated, the result of `~0' is converted to
`unsigned int'. Is my understanding of 6.3.1.3 correct that a negative
zero becomes a zero when converted to `unsigned int'?
Assuming that ~0 is not a trap representation on this ones-complement
machine, then the C code would have to convert the ones-complement negative
zero (which is indistinguishable from the intended ~0) to a positive zero
(which would be binary zero).
If I'm right so far, the expression `~0&0x1f<<1' either causes undefined
behavior (`~0' is a trap representation) or yields the value `0' on a
one's complement implementation.
Again assuming that ~0 isn't a trap value, then the arithmetical result of
anding a value with a zero (the result of the conversion of the
ones-complement negative zero to a usable positive zero) is zero.
But even in the latter case, the type of `~0&0x1f<<1' is `unsigned int',
so the fact that it corresponds to a "%d" format specifier causes
undefined behavior. An implementation is therefore free to write the
string "Someone called Dennis Ritchie has just been born.\n" to standard
output.
And thus we complete the process.
Did I get it right?
--
Lew Pitcher, IT Consultant, Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group
(Opinions expressed here are my own, not my employer's)