(no title)
detrino | 9 years ago
void TestSigned(int min, int max, int step) {
for (int i = max; i >= min; i -= step) F(i);
}
Becomes this with unsigned: void TestUnsigned(unsigned min, unsigned max, unsigned step) {
while (true) {
F(max);
if (max < min + step) break;
max -= step;
}
}
Now if I want to transform my loop to operate on pointers or iterators, the transformation is trivial: void TestUnsigned(unsigned *min, unsigned *max, unsigned step) {
while (true) {
F(*max);
if (max < min + step) break;
max -= step;
}
}
Quick: Do the same for yours.
dsfuoi|9 years ago
The second example causes unexpected behavior (and probably ub later) if: min + step > MIN_TYPE_MAX
The last example causes undefined behavior if: max - min < step - 1.