www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/26/12:16:30

From: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
Organization: Materials Science Centre
To: djgpp AT delorie DOT com
Date: Wed, 26 Feb 1997 17:00:52 GMT
Subject: Re: C++ packed structs..
Message-ID: <36629024DD7@fs2.mt.umist.ac.uk>

  Olav Kindt <kindt AT cmr DOT no> wrote:-

> ... The faq says that a struct like
> struct {char name[7];	unsigned long offset; double quality;
> 	} __attribute__ ((packed));
> will be packed correctly when compiled as C-source. Then it says that
> C++ doesn't allow this, and you must declare each struct field with the
> packed attribute. Does this in effect mean this :
> 	struct {
> 		char name[7] __attribute__ ((packed));
> 		unsigned long offset __attribute__ ((packed));
> 		double quality __attribute__ ((packed)); 	};

  I don't trust the compiler. Best put the `packed' in explicitly before every
`;' inside the { }. Better, save a bit of program size, thus:-
#define pk __attribute__ ((packed))
> 	struct {char name[7] pk;
> 		unsigned long offset pk;
> 		double quality pk; 	};

- Raw text -


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