Semicolon in C++?

后端 未结 9 1635
心在旅途
心在旅途 2020-12-16 11:07

Is the \"missing semicolon\" error really required? Why not treat it as a warning?

When I compile this code

int f = 1
int h=2;

the

9条回答
  •  感动是毒
    2020-12-16 11:29

    It's very good that the C++ compiler doesn't do this. One of the worst aspects of JavaScript is the semicolon insertion. Picture this:

    return
      (a + b);
    

    The C++ compiler will happily continue on the next line as expected, while a language that "inserts" semicolons, like JavaScript, will treat it as "return;" and miss out the "(a + b);".

    Instead of rely on compiler error-fixing, make it a habit to use semicolons.

提交回复
热议问题