|
|
|
|
|
by dastbe
3957 days ago
|
|
So the article isn't wrong, but its misleading you into thinking this should be correct for the wrong reasons. They are using signed integers as their indices, which means that the signed bit is always 0. Thus the addition after casting to unsigned will never overflow, and you can divide by two (shift by 1) and then recast to a signed integer, no harm no foul. |
|
In other words, C allows that UINT_MAX == INT_MAX, in which case you will overflow.
If they made that assumption, they should explicitly mention it, but they didn't.
> Update 17 Feb 2008:... ...Now that we've made this change, we know that the program is correct;)
It seems the article is aware of the irony. Another update would be in order.