Re:Almost Always Unsigned
by hamburglar on Sunday January 02, 2022 @04:56AM
(#29767335)
The suggestion of using an unsigned loop counter starting at size-1 and decrementing until “i<size” is no longer true starts this article off with a “this is bad advice” flavor to it in my book. If I encountered that code I’d stare at it way longer than necessary because I’d be trying to figure out what cleverness is hidden in the bizarre/backwards way the loop continuation test is written. I don’t know why you’d do this to someone else who has to read your code.
[ Parent
| on HN ]
It's an idiom - obviously very little known, likely less known than comparing floats to themselves being a NaN check.
The standard idiom for doing a reverse loop would be: "for (int i = size; i-- > 0; ) ...". As a side benefit it has lower registry pressure. Some folks have issues reading that one as well.
Saying all that not being 'unsigned fan', just the popularity of the idioms comes with their use frequency, and given that 'unsigned; is not popular at all...
Re:Almost Always Unsigned
by reallybigballs on Sunday January 02, 2022 @05:16AM
(#29767445)
reverse iteration seems pretty basic …