问题
Why is empty struct in C a constraint violation? Why does this rule get changed in C++?
Are there any historical reasons?
回答1:
since you don't have inheritance in C you don't need them. If you just want to have a distinguishable pointer type you can use pointers to incomplete types.
struct opaque;
struct opaque* stranger = 0;
should work fine.
回答2:
My guess is this:
In C, there isn't inheritance, templates, and function overloading - three major reasons we use empty structs in C++ - as a base interface, as a template parameter, as a type to help overload resolution.
Can you think of any real use of an empty struct in C?
来源:https://stackoverflow.com/questions/5361220/empty-struct-in-c-vs-empty-struct-in-c