[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Programming question: sizeof struct?



Joop Stakenborg <aba@casema.net> writes:

> For instance, if the structure were:
> 
> struct foo {
>     char text[3];
>     int  num;
> };
> 
> sizeof would return 6 and not 5.  So it's obvious that the compiler is
> placing a pad byte between text and num to align num.  I want it to
> stop!

Actually thats 8 on alpha.
And if you pack that to 5 the program will run with 10% speed and
generate a lot of unaligned traps. DON'T do that. Write a parser that
can read the data from file in a arch independant manner.

If you don't you will get a critical bug as soon as you release the
package, because if won't work on different endianess, even if you
pack the struct.

May the Source be with you.
			Goswin


Reply to: