-2

Can someone explain why this block of code is valid syntax? Why does it compile?

void foo(){}
enum class X { X1, X2 };

int main()
{
    auto s = X::X1;
    foo(),s = X::X2;
    return 0;
}

Using Apple LLVM version 9.0.0 (clang-900.0.38).

Edit:

The line in question as Some Programmer Dude mentioned foo(),s = X::X2;

0gap
  • 21
  • 7

1 Answers1

2

Assuming you mean

foo(),s = X::X2;

That's actually equal to

(foo()),(s = X::X2);

That is, it's the expression foo() which calls the foo function, and the expression s = X::X2, divided by the comma operator.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621