I did a search and Ive not found anything in my query. I am currently debugging the C optimizer, and the corresponding code is as follows:
while( x-- ) array[x] = NULL;
What should happen in this case? And should the result of this logic be consistent across all compilers?
Assume that the initial value of x in this case is 5.
The problem is that the program worked, I understand that it is caused by a reference to a negative array element.
Any help would be appreciated.
x -1 ( , x ), array[-1] . - array[0]. .
x
-1
array[-1]
array[0]
, , . array[x] , array[-1].
array[x]
, , , , unsigned .
unsigned x; int a[5]; for (x = 5; x-- > 0; ) a[x] = 0;
. ( , x >= 0 .) , - , - , . (, ).
x >= 0
x 5, :
array[4] = NULL; array[3] = NULL; array[2] = NULL; array[1] = NULL; array[0] = NULL;
x , x -1; .
, x while ( ). , x -1, while ( ). while array x .
while
array