Mail Archives: djgpp/1995/08/15/06:24:04
In article <DD5MGr DOT 8AE AT jade DOT mv DOT net>, "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk> writes:
|> If I have this struct:-
|>typedef struct{char miaow; int mice_caught,birds_caught; char*name;} cat;
|> and it needs to be packed, i.e. the fields starting at bytes 0, 1, 5, 9, and
|>the whole struct exactly 13 bytes long with no extra bytes inserted to fill
|>out to a multiple of 2 or 4, should I insert `__attribute__((packed))' after
|>`cat', or before any `;' where djgpp would otherwise be tempted to insert
|>filling bytes, or where?
|>
You should put __attribute__ ((packed)) after each member of the
structure. Don't try to work out which members need it and which
do not ; different releases of gcc may change what they do here,
and if you want to port the code to other platforms the rules
may well be different again (e.g. some systems need 8-byte alignment
rather than 4-byte alignment to get performance gains.)
You don't need to put it after the 'cat'. If you really care about how
big this structure is and you also care about portability, you won't
use 'int', but some other typedef'ed type which guarantees you get
a 4-byte integer. ('int' alone might give you 2, 4 or eight bytes
on systems that are within 20 feet of where I'm writing this ; there
may be other, more exotic possibilities.)
-----------------------------------------------------------------------------
Kevin Ashley K DOT Ashley AT Ulcc DOT ac DOT uk
Systems Development Group Manager http://www.ulcc.ac.uk/staff/Kevin+Ashley
University of London Computer Centre. ...ukc!ncdlab!K.Ashley
This is not a signature
- Raw text -