Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!uunet!munnari.oz.au!ariel!ucsvc.ucs.unimelb.edu.au!lu!cchd From: CCHD@lure.latrobe.edu.au (Huw Davies - La Trobe University Computer Centre) Newsgroups: comp.sys.mips Subject: Unaligned struct access (how to) Message-ID: <5054@lure.latrobe.edu.au> Date: 13 Feb 91 17:30:08 GMT Organization: VAX Cluster, Computer Centre, La Trobe University Lines: 41 I have a slight problem with the c compiler (on MIPS 120/5 running RISC/os 4.5.1). The following code doesn't do what I want :-) Please note that this is an example of the error extracted from debugging 6K lines of c code (It took a while to find....). $ more test_struct.c #include struct test { short a; int b; } c; main() { printf("a: %x\nb: %x\nSize of a: %d\n", &c.a, &c.b, (int) &c.b - (int) &c.a); } $ ./test a: 2003e460 b: 2003e464 Size of a: 4 $ I would have liked the difference in address to be 2, not 4. I know that there are efficiency reasons for aligned access, but I would like to be able to override the default. For those few of you who read comp.unix.aix as well (there's got to be someone else who believes in vendor independence...) I have the same problem with our RS/6000 systems. (Different implementation - same bugs :-) Huw Davies Computing Services e-mail: cchd@lucifer.latrobe.edu.au