if (x > y) { // Single-branch if-statement!!! int tmp; // The one and only branch consists tmp = x; // of the block. x = y; y = tmp; } ; // empty statement else // ERROR!!! "parse error before else" do_something();
问题是分号(;)出现在块后面。解决这个问题可以用do{}while(0):
if (x > y) do { int tmp; tmp = x; x = y; y = tmp; } while(0); else do_something();