delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/26/06:15:12

Xref: news2.mv.net comp.os.msdos.djgpp:6425
From: broeker AT I_should_put_my_domain_in_etc_NNTP_INEWS_DOMAIN (Hans-Bernhard Broeker)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: struct problem
Date: 25 Jul 1996 10:54:42 GMT
Organization: I need to put my ORGANIZATION here.
Lines: 20
Message-ID: <4t7jpi$nvl@news.rwth-aachen.de>
References: <4t5kbn$77 AT news DOT charweb DOT org>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


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