Mail Archives: djgpp/1996/07/26/06:15:12
patrick fox (web183 AT charweb DOT org) wrote:
> I am writing a program that does binary file i/o with structures. I read
> in the faq about __attribute__((packed)) and how it pads fields
> otherwise. I used the packed mode but when I look at the file in a hex
> viewer, it is not packed. Also, the file will not read in another proram
> that uses the exact same structures (packed). Here is the structure
'__attribute__((packed))' must be appended to *each* member declaration
of your struct. It's not very intuitive, but that's the way it is. So yours
should be:
typedef struct res_hdr {
char res_sig __attribute__ ((packed));
int res_numentries __attribute((packed));
} res_header __attribute__((packed));
(The final one might even be superfluous). If memory serves, this is also
in the FAQ, isn't it?
Hans-Bernhard Broeker (Aachen, Germany)
- Raw text -