delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/05/10:15:04

Date: Sun, 5 Jan 1997 17:01:52 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Roland Nilsson <roland DOT nilsson AT communique DOT se>
cc: djgpp AT delorie DOT com
Subject: Re: __attribute__((packed)) on types
In-Reply-To: <5amq4k$dvk@news.luth.se>
Message-ID: <Pine.SUN.3.91.970105165834.22565A-100000@is>
MIME-Version: 1.0

On 4 Jan 1997, Roland Nilsson wrote:

> struct foo
> {
> 	char a;
> 	long b;
> } __attribute__((packed));
> 
> This will not compile - gcc thinks I forgot the ending ';', and it
> never recognizes the attribute. The error message:
> 
> foo.cc:5: semicolon missing after declaration of 'foo'

This doesn't work for C++ programs, AFAIK.  In C++, you need to declare 
each struct field with __attribute__((packed)), like so:

struct foo
{
      char a __attribute__((packed));
      long b __attribute__((packed));
};

> "packed:
>  This attribute, attached to an enum, struct, or union type definition, 
>  specified that the minimum required memory be used to represent the 
>  type. Specifying this attribute for struct and union types is equivalent 
>  to specifying the packed attribute on each of the structure or union 
>  members..."

Note that the above excerpt is from a Chapter called "C Extensions", not 
"C++ Extensions".

- Raw text -


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