2013-02-22 162 views
2

我的理解是,当评估C中的赋值语句时,还会返回赋值。
但是,当我运行下面的代码时,似乎并不是这样。当source_next_level(GLib队列)为空时,g_queue_pop_head()函数返回NULL,然后将其分配给current_q_node。
while循环条件检查中的!= NULL比较似乎没有评估此比较,因为即使在current_q_node为NULL时也进入了while循环。评估赋值语句的返回值

为什么while循环在g_queue_pop_head返回NULL时进入?

while((current_q_node = g_queue_pop_head(source_next_level)) != NULL); 
{ 
    if(current_q_node == NULL) puts("It doesn't seem this should ever be printed but it is"); 
} 

回答

5
while((current_q_node = g_queue_pop_head(source_next_level)) != NULL); 
                           ^^^ 

你有以上的额外;

+0

@ H2CO3,但你需要良好的眼睛来捕捉这种错误;) – ouah 2013-02-22 19:23:23

+0

谢谢,不知道我怎么没看到。 – 2013-02-22 19:23:41