3 ms·
If your version goes UB on a zero length input array, then I think the compiler not only wins, but wins by a lot. Obviously you can easily fix it, but the stat
by mnarayan01 10y ago
If your version goes UB on a zero length input array, then I think the compiler not only wins, but wins by a lot.
Obviously you can easily fix it, but the statement people generally make is "You can't beat the compiler" not "(You, me, whomever else [that was as far as I got], and/or a huge time investment) can't beat the compiler". All that said...people categorically saying "You can't beat the compiler" annoys me too (though in my case they're right; I can't).
- kayamon 10y agoIt only fails on a _negative_ count. Zero count works. If your program is passing around negative counts, it's already broken, and the exact specifics of where and when the brokenness manifests aren't particularly important. Technically I should have used a size_t instead of an int for the count anyway, so it's kinda a moot point. I just picked int to make a simpler toy example program.