When I try to compile the piece of code below, I get this warning:
warning: suggest parentheses around assignment used as truth value
Why does this happen? This is a rather common idiom, I believe. I even use something like it earlier on my code.
struct PIDList*
getRecordForPID(struct PIDList* list, pid_t pid) {
while(list = list->next)
if (list->pid == pid)
return list;
return NULL;
}
Be explicit - then the compiler won't warn that you perhaps made a mistake.
while ( (list = list->next) != NULL )
or
while ( (list = list->next) )
Some day you'll be glad the compiler told you, people do make that mistake ;)