Mail Archives: djgpp/1996/07/26/21:52:14
Reply to message 0373075 from BROEKER AT I_SHO on 07/25/96 6:54AM
>'__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?
Well, that's not exactly true - if you include the final one, the rest of them
are superfluous. :) So, it would be easiest to do something like this:
typedef struct res_hdr {
char res_sig;
int res_numentries;
} __attribute__((packed)) res_header;
Note that you must put __attribute__ ((packed)) BEFORE the name
of the variable, immediately after the closing brace of the struct
definition. Doing it the other way around packs only that ONE
variable, not ALL variables of type struct res_hdr.
Of course, if you're using C++, _none_ of the above will work due to
a bug in gcc; then you must surround your struct definition with
#pragma pack(1) and #pragma pack().
The FAQ mentions this, and points to the gcc docs where there's an
extensive description of all the abilities of the __attribute__() extension.
John
P.S.: Hans, I think there's something wrong with your mailer...
>From: broeker AT I_should_put_my_domain_in_etc_NNTP_INEWS_DOMAIN (Hans-Bernhard
Broeker)
???
- Raw text -