Path: utzoo!telly!attcan!uunet!cs.utexas.edu!samsung!usc!ucla-cs!uci-ics!rfg From: rfg@ics.uci.edu (Ron Guilmette) Newsgroups: gnu.gcc Subject: Re: packed structures in GCC 1.36? Message-ID: <256A4870.18732@paris.ics.uci.edu> Date: 22 Nov 89 07:19:11 GMT References: <6632@columbia.edu> Reply-To: Ron Guilmette Distribution: gnu Organization: University of California, Irvine - Dept of ICS Lines: 32 In article <6632@columbia.edu> ji@close.cs.columbia.edu (John Ioannidis) writes: >Hi! > >This topic has probably been discussed in the past, but I haven't been >reading gnu.gcc lately. So, suppose I have the following structure: > > struct _foo > { > char b1; > short w1; > short w2; > char b2; > }; > >On my machine (a 386 machine running 386/ix (System V R3.2)), the size >of _foo is eight bytes, with a "filler" byte between b1 and w1 and >another after b2. This is fine, and there are good reasons for doing >it. However, when I'm using that structure to access device registers... Try this: struct _foo { unsigned b1:8; unsigned w1:16; unsigned w2:16; unsigned b2:8; }; Note that ANSI requires the fields to be unsigned, but GCC probably doesn't care. // rfg