James said:
James Kanze wrote:
James Kanze wrote:
[...]
Well there's more than that, such as loop counter rollover.
If you insist on using a for loop
. When working down, I'd
normally write:
int n = top;
while (n > 0) {
-- n;
// ...
}
Which, of course, works equally well with unsigned.
Most of that gets subsumed by iterators now anyway, so even less of a
point is the loop control thing.
And of course, with iterators, you have to write the loop as
above (or use reverse iterators). You can't decrement once
you've encountered begin.
[...]
I don't think it's a provable thing, no matter who says it.
Programmers will have to think for themselves on this one.
Except that in the absence of any killer argument, you have to
go with what the majority of programmers expect. In fact, even
when there is a strong argument for something else, you may end
up having to go with what the majority of programmers expect.
[...]
No small potatoes, for simplifying maintenance is worth more
than "simplifying" original coding. The semantic correctness
and syntactic richness ("semantical" and "syntactical"?) is
what is compelling to me about unsigned.
The semantic correctness is in the eye of the beholder. You can
argue for any meaning you want, but in the end, the only meaning
that counts is what the reader understands. At least if your
goal is communicating.
How does the curriculum go? Do they teach unsigned as a
bit-based thing or as the complementary integer type to
signed?
They never mention it except in conjunction with the bitwise
operators.
Surely without such instruction, the novice will assume
unsigned is "the set of positive numbers that can be
represented with the given width".
Without any instruction, I suspect that the novice will assume
that unsigned behaves like a cardinal. I.e. that all of the
values of an unsigned will fit in an int (integer), and that
substraction of two unsigned will result in an int (and is
guaranteed to fit in an int).
Of course, without any instruction, the novice will assume that
division of two integers results in a rational number. Or at
least it's closest approximation, a float or a double.
And even more "of course": without any instruction, a novice
won't even know that unsigned exists. What he thinks of
unsigned is 100% conditioned by his instruction.
And in my experience, something like 95% of the programmers seem
to have learned it along the lines of what Stroustrup presents.