Mail Archives: djgpp/1995/01/28/15:10:19
On Fri, 27 Jan 1995, John E. Davis wrote:
> > printf("%d\n", sizeof(header));
> >
> >Which gave me 24 for output. If you look carefully, however, you will see
> >that it should be 22. Why is it giving be 24? Have no clue, but it must
> >be a bug. I actually checked the sizeof() of each field in the header
>
> I am afraid that the bug is in *your* program. You are depending upon the
> non-portable behavior of the structure being packed. As you have found out,
> gcc pads it. There might be some compiler switch to force the compiler to
> pack the structure but I would not rely on it.
The switch goes by the name of "__attribute__ ((packed))". I define it
to PACK so I can do stuff like this:
struct {
char a PACK;
short b PACK;
char c PACK;
}
Kim
- Raw text -