Ben Bacarisse wrote:
> Philip Potter <> writes:
>> From n1256, 6.5.12:
>> "The result of the | operator is the bitwise inclusive OR of the
>> operands (that is, each bit in the result is set if and only if at
>> least one of the corresponding bits in the converted operands is
>> set)."
>>
>> Seems to be defined in terms of representation to me.
>
> That is over-stating the case since the bits themselves are, earlier,
> defined in terms of the way in which they contribute to the value ("if
> there are N value bits, each bit shall represent a different power of
> 2 between 1 and 2**(N −1)"). The term "corresponding" does not need
> to be read as meaning "corresponding by position" -- the bits
> correspond by contributing the same power of two to the value.
Since the two operands are of the same type, "corresponding by position"
is equivalent to "corresponding by value" for all bits except padding
bits (which have no value).
> The representation does play a role in the result of bit operations on
> signed types because the value produced by changing the sign bit does
> depend on whether the system uses sign+magnitude, 1s complement or 2s
> complement for negative numbers -- but that is only one bit out of
> N+1.
If you're going to allow sign+magnitude, 1s complement and 2s complement
as different kinds of representation, then don't you also accept
"binary" as an unsigned representation? The fact that it's the only one
allowed doesn't preclude the fact that it specifies how integers are
represented. Therefore the representation plays a key role in the result
of bit operations - they are defined in terms of bits, which are a
representational artefact.
I guess this is simply a difference of opinion in what "representation"
means.
>> (In fact, it
>> seems to also operate on padding bits, though I'm not sure).
>
> It doesn't matter, since the padding bits don't contribute to the
> value, and no valid operation can produce a combination of padding
> bits that constitute a trap representation.
Define "valid operation". Looking at n1256, I guess you mean this
(6.2.6.1p

:
"Where an operator is applied to a value that has more than one object
representation, which object representation is used shall not affect the
value of the result.[43] Where a value is stored in an object using a
type that has more than one object representation for that value, it is
unspecified which representation is used, but a trap representation
shall not be generated."
I think this shows that padding bits are not necessarily involved in a
bitwise-OR operation and that it therefore it isn't defined in terms of
representation as defined in 6.2.6.1p4. Thanks for the correction. As
Eric Sosman says elsethread, this means the rest of the argument is
angels-on-pinheads territory.
n1256 certainly seems impossible to read unless you assume that
operators work on values (statements such as the fact that ~myuint is
equivalent to UINT_MAX - uint in the definition of the ~ operator
preclude the bitwise operators seeing padding bits) but I can't seem to
see this explicitly stated anywhere.