C: transitive (double) assignments

后端 未结 6 1164
半阙折子戏
半阙折子戏 2021-01-20 07:11

I have used such construct in C:

list->head = list->tail = NULL;

and now I consider whether this really mean what I suppose.

<
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-20 07:37

    Neither of them. It mean

    list->tail = NULL;
    list->head = list->tail;
    

    1 is incorrect because in case the type of list->tail is not a pointer, it may yield different result because the value will be converted to the type of the destination of the assignment.

    The order of two statements in 2 is incorrect.

提交回复
热议问题