www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/26/21:52:14

From: j DOT aldrich6 AT genie DOT com
Message-Id: <199607270147.AA081722069@relay1.geis.com>
Date: Sat, 27 Jul 96 01:23:00 UTC 0000
To: djgpp AT delorie DOT com
Mime-Version: 1.0
Subject: Re: struct problem

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019