3 ms·
> for (unsigned i = n - 1; i >= 0; i--) An defined behavior alternative: for( size_t i = n; i --> 0; )
by MaulingMonkey 11y ago
> for (unsigned i = n - 1; i >= 0; i--)
An defined behavior alternative:
for( size_t i = n; i --> 0; )
- ahomescu1 11y agosize_t is also unsigned (no idea why). The signed equivalent is ssize_t. Edit: Sorry, missed the "i-- > 0" at first. The code works, but not because of changing "unsigned" to "size_t".
- Peaker 11y agoSizes can be >2gb on a 32 bit system. Not sure how ssize_t works, is it 64 bits then? It makes sense to use unsigned for sizes to save a bit (or 32 bits per size). Also less invalid possible inputs to handle.
- MaulingMonkey 11y agoNo worries. I nearly left it "unsigned", but my OCD kicked in. Too many 64-bit conversion warnings stain my psyche...
- kazinator 11y agoBy the way, ssize_t is POSIX, from <sys/types.h>, not ISO C.