Top-Down Structs
    Regan Heath 
    regan at netwin.co.nz
       
    Sun Mar 12 01:08:59 PST 2006
    
    
  
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
    
    
More information about the Digitalmars-d-bugs
mailing list