Compiler warning - suggest parentheses around assignment used as truth value

前端 未结 3 1851
难免孤独
难免孤独 2020-11-29 03:41

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 t

3条回答
  •  情歌与酒
    2020-11-29 04:28

    While that particular idiom is common, even more common is for people to use = when they mean ==. The convention when you really mean the = is to use an extra layer of parentheses:

    while ((list = list->next)) { // yes, it's an assignment
    

提交回复
热议问题