3 ms·
It is against the rules. To fix that, you'd need to put a field of type 'struct Base' in the derived struct(s) rather than just copying its fields. edit: If y
by comex 8y ago
It is against the rules. To fix that, you'd need to put a field of type 'struct Base' in the derived struct(s) rather than just copying its fields.
edit: If you want to keep the existing syntax and can use GCC extensions, it should be legal to use an unnamed union:
struct Derived1 {
union {
struct Base base;
struct {
int a; int b; int c;
};
};
int d; int e;
};
edit2: or, with -fms-extensions, just
struct Derived1 {
struct Base;
int d; int e;
};
- ufo 8y agoPutting a field of type 'struct Base' adds extra padding in my case, unfortunately.
- loa-in-backup 8y agoI believe there is a way to disable field alignment on a case-by-case basis. I could be wrong, though.
- comex 8y agoYes, there's the GCC extension __attribute__((packed)), or #pragma pack, an extension supported by both GCC-style compilers and MSVC.