M
Matt
I'm sure I've read somewhere that it's considered bad practice to modify
the value of the variable on the right of a comparison operator inside
the loop concerned. If I have remembered this correctly then what is the
usual way to do this:
int del_at(int i, int len, type arr[])
{
int j;
for(j = i + 1; j < len; j++, i++)
arr = arr[j];
return len - 1;
}
and somewhere else:
type arr[len];
/*fill it with some items*/
int i;
for(i=0; i < len; i++){
if(needs_deleting(arr))
len = del_at(i, len, arr);
}
This code works as intended and isn't complained about by gcc -Wall.
Isn't one of the things about C that you're able to do what you want?
Why shouldn't I do it the way I showed above? Could it come back to bite
me somehow?
Matt.
the value of the variable on the right of a comparison operator inside
the loop concerned. If I have remembered this correctly then what is the
usual way to do this:
int del_at(int i, int len, type arr[])
{
int j;
for(j = i + 1; j < len; j++, i++)
arr = arr[j];
return len - 1;
}
and somewhere else:
type arr[len];
/*fill it with some items*/
int i;
for(i=0; i < len; i++){
if(needs_deleting(arr))
len = del_at(i, len, arr);
}
This code works as intended and isn't complained about by gcc -Wall.
Isn't one of the things about C that you're able to do what you want?
Why shouldn't I do it the way I showed above? Could it come back to bite
me somehow?
Matt.