From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24811 invoked by alias); 16 Jan 2014 10:45:20 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 24801 invoked by uid 89); 16 Jan 2014 10:45:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-oa0-f44.google.com Received: from mail-oa0-f44.google.com (HELO mail-oa0-f44.google.com) (209.85.219.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 16 Jan 2014 10:45:18 +0000 Received: by mail-oa0-f44.google.com with SMTP id g12so2687497oah.3 for ; Thu, 16 Jan 2014 02:45:16 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.60.92.102 with SMTP id cl6mr1302732oeb.59.1389869116722; Thu, 16 Jan 2014 02:45:16 -0800 (PST) Received: by 10.182.105.69 with HTTP; Thu, 16 Jan 2014 02:45:16 -0800 (PST) Date: Thu, 16 Jan 2014 10:45:00 -0000 Message-ID: Subject: RE: structure packing From: vijay nag To: "gcc-help@gcc.gnu.org" Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes X-SW-Source: 2014-01/txt/msg00063.txt.bz2 Dear gcc, Why is the size of below struct UnPackedStruct 6 ? Is there any switch similar to -E in gcc to check how data alignment is performed by GCC for structs ? #include #include struct tlv_header_t { unsigned char tlv_length_upper : 3; unsigned char reserved : 5; unsigned char tlv_length_lower; uint16_t tlv_type; }; typedef struct { struct tlv_header_t sess; uint8_t p; } UnPackedStruct; typedef struct { int a; char b; } PaddedStruct; int main() { UnPackedStruct a; PaddedStruct b; printf("size of a = %u\n", sizeof(a)); printf("size of b = %u\n", sizeof(b)); return 1; } ./padding size of a = 6 size of b = 8