Why is empty struct in C a constraint violation? Why does this rule get changed in C++?
Are there any historical reasons?
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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With