Top-Down Structs

Brad Roberts braddr at puremagic.com
Sun Mar 12 10:49:36 PST 2006


On Sun, 12 Mar 2006, Bob W wrote:

> "Regan Heath" <regan at netwin.co.nz> wrote in message 
> news:ops6amc90r23k2f5 at nrage.netwin.co.nz...
> > On Sun, 12 Mar 2006 02:02:48 +0100, Bob W <nospam at aol.com> wrote:
> >> I just wanted to add this info:
> >>
> >> Check INPUT_RECORD.sizeof if it is declared before
> >> and after its related sub-structs. In the first case
> >> the size of INPUT_RECORD will be 4, otherwise the
> >> size is 20.
> >
> > Interestingly naming the union fixes the problem. eg.
> >
> > struct INPUT_RECORD {
> > WORD EventType;
> > union bob {
> > KEY_EVENT_RECORD KeyEvent;
> > MOUSE_EVENT_RECORD MouseEvent;
> > WINDOW_BUFFER_SIZE_RECORD WindowBufferSizeEvent;
> > MENU_EVENT_RECORD MenuEvent;
> > FOCUS_EVENT_RECORD FocusEvent;
> > }
> > bob a;
> > }
> >
> > (rest of wrong declaration order as given by OP)
> >
> > results in an INPUT_RECORD.sizeof of 20. I think the bug lies in the 
> > handling of anonymous unions.
> >
> > Regan
> 
> Good job! Looks like a usable workaround. But in the long term I would
> rather like to see the D compiler to stick to its promises:
> 
> "anonymous structs/unions are allowed as members of other structs/unions"

Would one of you finish minimizing the test case and file it in bugzilla?

Thanks,
Brad



More information about the Digitalmars-d-bugs mailing list