This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: struct __attribute((packed));

>>>>> "E" == E Weddington <> writes:

 E> Paul Koning wrote: According to the docs here:
 E> <>
 E> what about doing something like this?:
 E> typedef int packed_int __attribute__ ((aligned (1)));
 E> packed_int *ppi;
 >> That would make sense, but it has never worked for me.  It seems
 >> that attributes don't apply to type names, only to variables and
 >> members.
 E> What?! That whole section in the docs talks about attributes on
 E> types. If it doesn't work as described, then the docs need some
 E> serious rework.

I'd rather the compiler got the work than the docs.

Maybe it's better in newer versions; I don't have anything newer than
3.4.1 built right now.

Test program:

typedef int pi __attribute__((packed));

void set(void *p, int v)
    pi *ppi;
    ppi = (pi *) p;
    *ppi = v;

On 3.3.3, this compiles without any warnings (in spite of -Wall) but
the store is an aligned store (MIPS "sw" instruction).

With 3.4.1, I get this:

test.c:1: warning: `packed' attribute ignored


And yes, I agree with Dave that having attributes work syntactically
the same as CV-modifiers -- so they can be directly applied to the
pointed-to type in pointer declarations -- would be a Good Thing.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]