A previous post of mine raised the topic of anonymous structs, with several commentators saying these were not allowed in C++.
Here is a construction that I use a lot: is this legal C++?
const int HeaderSize = 8192;
struct Header
{
union
{
struct
{
int r;
// other members
};
unsigned char unused[HeaderSize]; // makes Header struct's size remain constant as members are added to the inner struct
};
// Default constructor
Header()
{
}
};
In Standard C++ there cannot be an anonymous struct (see here for why), although mainstream compilers offer it as an extension.
I guess you intend to read binary data directly into this struct. That is frowned on in Modern C++, and it is preferred to use data serialization .
If you persist with reading directly to the struct perhaps an alternative would be: