Semicolon at the ends of if-statements and functio

2020-02-13 07:21发布

I just ran into some code that overuse semicolons, or use semicolon for different purposes that I am not aware of.

I found semicolons at the end of if-statements and at the end of functions. For instance:

int main (int argc, char * argv[]) {
    // some code

    if (x == NULL) {
        // some code
    };  <-----

    // more code

    return 0;
}; <---

It is compiling with cc, not gcc. What do those semicolons do? I'm assuming that there is no difference because the compiler would just consider it as empty statement.

标签: c
7条回答
闹够了就滚
2楼-- · 2020-02-13 07:58

These semicolons are useless as others have pointed out already. The only thing I want to add is that IMO, these are optimized out anyway i.e., compiler doesn't generate any real code for these.

查看更多
登录 后发表回答