Aligned access to c structures (how to avoid)

Huw Davies - La Trobe University Computer Centre CCHD at lure.latrobe.edu.au
Thu Feb 14 03:45:17 AEST 1991


I have a slight problem with the AIX v3 c compiler (on an RS/6000).
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 <stdio.h>

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. 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.

Huw Davies
Computing Services

e-mail: cchd at lucifer.latrobe.edu.au



More information about the Comp.unix.aix mailing list