From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1575 invoked by alias); 10 Sep 2002 17:29:23 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 1556 invoked from network); 10 Sep 2002 17:29:22 -0000 Received: from unknown (HELO av.mvista.com) (12.44.186.158) by sources.redhat.com with SMTP; 10 Sep 2002 17:29:22 -0000 Received: from mvista.com (av [127.0.0.1]) by av.mvista.com (8.9.3/8.9.3) with ESMTP id KAA02295 for ; Tue, 10 Sep 2002 10:29:21 -0700 Message-ID: <3D7E2A9F.9325CF8D@mvista.com> Date: Tue, 10 Sep 2002 10:29:00 -0000 From: John Kwan X-Accept-Language: en MIME-Version: 1.0 To: gcc@gcc.gnu.org Subject: The pack attribute Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2002-09/txt/msg00377.txt.bz2 Consider the following program: // *************** test.c #include // case 1 typedef struct { unsigned char byte1; int i; unsigned char byte2; } test_struct_1 __attribute__((packed)); // case 2 struct test_struct_2 { unsigned char byte1; int i; unsigned char byte2;test_struct_1 var1; } __attribute__((packed)); test_struct_1 var1; struct test_struct_2 var2; main() { printf("SIZE of var1 = %d\n",sizeof(var1)); // prints 12 bytes printf("SIZE of var2 = %d\n",sizeof(var2)); // prints 6 bytes } //**************** end of program Intuitively I would expect case 1 and case 2 to product the same result but they do not. The 3.1.1 gcc compiler prints 12 for case 1 and 6 for case 2. The gcc on line manual states: "specifying this attribute for struct and union types is equivalent to specifying the pack attribute on each of the structure or union members" This seems to imply that case 1 should also be 6 bytes in size. However, 2lines later, the manual further states: "You may only specify this attribute after the closing curly brace on an enum definition not in a typedef declaration ..." This seems to imply that __attribute__((packed)) does not work on the typedef of an enum. No mention is made about structure/union typedefs. My question is: Should case 1 and case 2 work differently? Or is this feature badly implemented. Thanks. JOhn W Kwan MontaVista Software