When you perform a comparison d <= (TOTAL_ELEMENTS-2), type conversion is performed. dhas a type signed int, but (TOTAL_ELEMENTS-2)has a type size_tthat is an unsigned type. C rules say that when an operator has a signed and unsigned argument, and the unsigned argument is larger or equal to the signed argument, the signed argument is converted to unsigned.
That is, the comparison ends as:
(size_t) d <= (TOTAL_ELEMENTS-2)
size_t , (size_t) -1 - , , -1. 32- size_t 2 32 - 1 = 4 294 967 295.
, int:
d <= (int) (TOTAL_ELEMENTS-2)
, , ..
. gcc, , , -Wall -Wextra:
$ gcc -o arrayprint -Wall -Wextra -ansi arrayprint.c
arrayprint.c: In function βmainβ:
arrayprint.c:11: warning: comparison between signed and unsigned