I got warning:
Pe186 \"Pointless comparison of unsigned int with zero\"
when I tried to compile the following code:
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11) in Centos 7 x86_64 does not give the warning.
But when loop index is decremented to -1
, loop index is implicitly converted to a value which is equal to UINT_MAX (limits.h)
UINT_MAX + 1u is equal to 0
. 0 - 1 is equal to UINX_MAX
.
limits.h Various platform-dependent constants proposed by ANSI
One of alternative solution is:
unsigned int clLoop, i;
for(i = cpLoopStart+1, clLoop = i-1; i > 0; i--, clLoop = i-1)
{
//Do something
}
i
will change in the range [1, cpLoopStart+1]
clLoop
will change in the range [0, cpLoopStart]