warning: ISO C++ prohibits anonymous structsstruct vec {
union {
struct {
double x, y, z;
} s;
double v[3];
};
};--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/8dadb4a9-7487-4328-a79d-3e289e9ec613%40isocpp.org.
the type punning that those unions are often used for in C is not valid in the C++ type system, except for very specific cases.
Standardeze technicalities aside, there is no reason my example shouldn't work, especially since compilers already need to support it for C11.
Maybe this one can be added as a defect report? How does one report a defect?
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/fbddb859-f325-4789-ab2c-0b78a1af2837%40isocpp.org.
struct Foo {
struct Bar {
int i;
};
};
C and C++ are two different and now diverging languages.
C has no notion of nested structs so when you write this:You are defining an empty struct Foo and the definition of Bar is just discarded.struct Foo {
struct Bar {
int i;
};
};
While in C++, you also define Foo::Bar.
What I want to highlight: the behavior of the two languages is already different without considering anonymous structs. So just because C does it is not a valid reason to put it in C++.
That being said, I think it is still a valuable feature for C++ on its own.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposal...@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/33180627-ede8-4e04-b7c5-3b9c67a146a0%40isocpp.org.
On 10/04/2018 07:52 AM, floria...@gmail.com wrote:
C and C++ are two different and now diverging languages.
C has no notion of nested structs so when you write this:You are defining an empty struct Foo and the definition of Bar is just discarded.struct Foo {
struct Bar {
int i;
};
};
Bar isn't actually discarded; it is still a defined class at file scope in C:
struct Foo {
struct Bar {
int i;
};
};
struct Bar b = { 1 }; // Ok in C, ill-formed in C++ (Bar is an incomplete type)
But that means the difference is even bigger than what I expected, and that makes the argument "it's already in C11" even less relevant.