Why does C need “struct” keyword and not C++?

后端 未结 6 784
臣服心动
臣服心动 2020-11-27 03:38

I\'ve always been a little confused about what\'s going on here:

#include 

int main() {  
    timeval tv;
    tv.tv_sec = 1;

    for (;;) {
         


        
6条回答
  •  余生分开走
    2020-11-27 04:23

    Syntactically both treat struct almost the same. Only C++ has added an extra rule that allows to omit the struct (and class) keyword if there is no ambiguity.

    If there is ambiguity, also C++ requires the struct keyword in some places. A notorious example is stat on POSIX systems where there is a struct stat and a function stat.

提交回复
热议问题