Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!hp4nl!orcenl!bengsig From: bengsig@dk.oracle.com (Bjorn Engsig) Newsgroups: comp.unix.aix Subject: Re: Aligned access to c structures (how to avoid) Message-ID: <1254@dkunix9.dk.oracle.com> Date: 14 Feb 91 10:03:37 GMT References: <5053@lure.latrobe.edu.au> Reply-To: bengsig@dk.oracle.com (Bjorn Engsig) Organization: Oracle Denmark Lines: 30 Article <5053@lure.latrobe.edu.au> by CCHD@lure.latrobe.edu.au (Huw Davies - La Trobe University Computer Centre) says: | |struct test |{ | short a; | int b; |} c; | | printf("a: %x\nb: %x\nSize of a: %d\n", &c.a, &c.b, | (int) &c.b - (int) &c.a); | |a: 2003e460 |b: 2003e464 |Size of a: 4 | |I would have liked the difference in address to be 2, not 4. The ANSI C standard does actually allow the implementor to add padding between any structure member (not before the first one), so you should not make assumptions about this. I'm afraid you will need to rewrite your code to make it behave the way you want, i.e. declare the structure differently and do the packing in and out yourself. | I have searched high and low all |over our CD-ROM and can't find an option to the c compiler to force |the slow (but nice) way. Personally, I don't see what is nice about it, but I do of course not know your application. -- Bjorn Engsig, ORACLE Corporation, E-mail: bengsig@oracle.com, bengsig@oracle.nl "Stepping in others footsteps, doesn't bring you ahead"