Why use different a different tag and typedef for a struct?

后端 未结 5 514
离开以前
离开以前 2020-12-09 20:11

In C code, I\'ve seen the following:

typedef struct SomeStructTag {
    // struct members
} SomeStruct;

I\'m not clear on why this is any d

5条回答
  •  萌比男神i
    2020-12-09 20:56

    The reason is that struct tags and typedef names are in different namespaces in C. You can only use a struct tag after the keyword struct, so it is handy to know which is which.

    In C++ they are in the same namespace so the issue doesn't arise. Which also means your second example may not be legal C++. Your first example is legal in both languages.

提交回复
热议问题