Mail Archives: djgpp/1999/03/09/07:33:47
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 -