简单描述问题,请看下面的代码:
int main()
{
int a=123;
({if (a) a=0;});
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我收到了[-Wsequence-point]的警告
Line 4: warning: operation on 'a' may be undefined
Run Code Online (Sandbox Code Playgroud)
我的g ++版本是4.4.5
无论谁解释这个简单的问题,我都会感激不尽.
顺便说一句,你可以在这个中文网站的#7中找到我的原始程序和原始问题(不是必需的)
UPD1:
虽然改变代码({if(a) a=0; a;})可以避免警告,但我认识到问题的真正原因可能不是The last thing in the compound statement should be an expression followed by a semicolon.
因为纪录片还说If you use some other kind of statement last within the braces, the construct has type void, and thus effectively no value.
一个例子可以显示它:
int main()
{
int a=123, …Run Code Online (Sandbox Code Playgroud)