delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/03/09/07:33:47

Date: Tue, 9 Mar 1999 12:21:59 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Rich Dawe <rd5718 AT irix DOT bris DOT ac DOT uk>
cc: djgpp AT delorie DOT com
Subject: Re: Real stupid problem.
In-Reply-To: <F89y29.Asz@fsa.bris.ac.uk>
Message-ID: <Pine.SUN.3.91.990309122114.7248a-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Mon, 8 Mar 1999, Rich Dawe wrote:

> : struct SXM_Pat_header {
> :    int pat_size __attribute__ ((__packed__));
> :    char pack_type __attribute__ ((__packed__));
> :    short nr_rows __attribute__ ((__packed__));
> :    short pattern_data_size __attribute__ ((__packed__));
> : };
> 
> 	You can just put the attribute at the end of the structure too:
> 
> 	struct SXM_Pat_header {
> 		<blah>
> 	} __attribute__((packed));
> 
> This saves a lot of typing!

But note that this doesn't work in C++, only in C.  In C++ you need to
put the attribute after each struct member.  (FAQ section 22.10.)

> BTW I don't think you need the double
> underscores on the packed part - it works for me without. Is it supposed
> to have double underscores?

GCC accepts both, but -ansi complains if you don't use the
underscores.  It is always safer to have the underscores when you use
non-standard extensions (like __inline__ etc.), they run a lesser risk
of clashing with some global symbol defined by some third-party software.

- Raw text -


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