Forcing gcc to odd byte alignment?

Forcing gcc to odd byte alignment?

Post by John Ph » Sat, 01 May 1999 04:00:00



Is it possible to force gcc to odd byte alignment?

For example, if I had the following code fragment:

typedef struct {
        char element_1;
        int element_2;

Quote:} test_struct;

main()
{
        test_struct x;
        printf("sizeof(x)=%d", sizeof(x));

Quote:}

Is there any gcc compilation switch that will cause sizeof(x) to
return a 5 instead of 8 bytes?

I've looked through the gcc man pages and it doesn't look like
it supports odd byte alignment. Can someone confirm.

Thanks,

John

 
 
 

Forcing gcc to odd byte alignment?

Post by Neil Ricke » Sat, 01 May 1999 04:00:00



>Is it possible to force gcc to odd byte alignment?
>For example, if I had the following code fragment:
>typedef struct {
>    char element_1;
>    int element_2;
>} test_struct;
>main()
>{
>    test_struct x;
>    printf("sizeof(x)=%d", sizeof(x));
>}
>Is there any gcc compilation switch that will cause sizeof(x) to
>return a 5 instead of 8 bytes?

Suppose you could do this.  Then somebody uses malloc() to
dynamically allocate such a structure.  Since malloc() does not give
segments with odd alignment, you will have misaligned data, and on
some system this will give bus errors.