2

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

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

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");
}
4

1 回答 1

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

你有一个额外的;上面。

于 2013-02-22T19:16:09.187 回答