This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: How to stop gcc padding structs???


On Mon, Jan 29, 2001 at 11:44:57AM -0600, Grant Edwards wrote:
> 
> > > > > > Relying on sizeof to do this is *very* non-portable.
> > > > > 
> > > > > It's a device driver for a specific board.  It doesn't really
> > > > > need to be portable.
> > > > 
> > > > The fact that it is a device driver for a specific board means that
> > > > you're not going to try to port it to a different board.  But
> > > > well-written device drivers do get ported to different operating
> > > > systems, or compiled with different compilers.  For example, one
> > > > reason why you might want to port to a different compiler is that you
> > > > might discover that the compiler you're using is buggy.  Note that
> > > > even upgrading to a later version of the same compiler may expose you
> > > > to some of the same portability issues.
> > > 
> > > True.  I suppose for maximum portability I should just use
> > > pointer arithmatic with hard-wired offsets.  It's just so ugly.
> > 
> > Which of course will not work so well if your device is put into a non-x86 or
> > non-ppc that traps when given an unaligned pointer (ie, a normal RISC
> > machine).
> 
> If the board is redesigned with a different processor, then the
> bus-interface logic that hooks up to the peripheral chip would
> have to change.
> 
> I wasn't aware of any popular processors that had alignment
> requirements for chars.  The variables I'm trying to get mapped
> to specific addresses are chars.

Well there is the original Alpha, which had to use hacks to get around the
problem of not having byte/16-bit access instructions at the device layer (and
multiple instructions to pack/unpack the values).

What I thought you meant was something like:

	int i = *(int *)((char *p) + 14);

Ie, unaligned word access (the x86 always allows unaligned accesses albeit at a
performance penalty, as do the high-end powerpc's in big endian mode).

-- 
Michael Meissner, Red Hat, Inc.  (GCC group)
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work:	  meissner@redhat.com		phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org	fax:   +1 978-692-4482

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]