J
James Kanze
Presumably "works for any representation" meant that things
OTHER than unsigned were being considered, since unsigned
types use two's complement and nothing else.
Given that two's complement specifies how to represent negative
values, given a base 2 representation for positive values, I
don't see how one can say that unsigned types use two's
complement.
And it's true, said expression does NOT work for
representations other than two's complement. Since almost
everything uses two's complement these days, said expression
will thus work even for signed types on almost everything.
For some sufficiently weak definition of "almost". Whether you
like it or not, machines are still being sold that don't use
two's complement, and at least one of them supports C++. If the
only machines you have to worry about are PC's, fine. You can
ignore portability issues. Otherwise...