Expression “variable, variable = value;”

后端 未结 4 942
[愿得一人]
[愿得一人] 2021-01-19 06:43

I have been looking through some MFC code and i came across this expression. It was in OnInitDialog() function, didn\'t look like it\'s MFC specific. The variables had some

4条回答
  •  春和景丽
    2021-01-19 07:00

    This is likely an error in the program. The statement

    a, b = c;
    

    Is completely equivalent to

    b = c;
    

    Since the comma operator evaluates from left to right and discards all values except the last. Since the expression a has no side effects, it's essentially a no-op.

    I would suspect that this is either programmer error or an incorrect translation of code from a different language into C++. You should contact the author to let them know about this.

    Hope this helps!

提交回复
热议问题