c++csyntaxlanguage-design

Why are empty statements legal?


int main()
{
    int var = 0;; // Typo which compiles just fine
}

In both C and C++, this is allowed because an expression-statement may be just a ;, which makes it a "null statement". Why is this allowed?


Solution

  • This is the way C and C++ express NOP.