Expression “variable, variable = value;”

后端 未结 4 963
[愿得一人]
[愿得一人] 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:04

    Does this make any sense in C++?

    Yes syntactically it does, but without comments you may not know the developers intentions were (if any) other than maybe suppressing a variable warning.

    Is a variable name also an expression?

    Yes a variable itself is an expression. Ex. if() if(something)

    This code does compile, so how does this work?

    It works by using the comma operator and ignoring the result of something then assigning 0 to somethingElse. Although something was marked volatile the original developer may of had a compiler that still complained about unused variables and being the clever developer he or she was then decided to suppress with that syntax.

提交回复
热议问题