From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from fencepost.gnu.org (fencepost.gnu.org [IPv6:2001:470:142:3::e]) by sourceware.org (Postfix) with ESMTPS id 111C03858C60 for ; Tue, 26 Oct 2021 23:23:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 111C03858C60 Received: from [2a00:1370:8125:40ec:606e:d2d2:e43:5201] (port=40342 helo=corvax) by fencepost.gnu.org with esmtpa (Exim 4.90_1) (envelope-from ) id 1mfVnK-0002LZ-CS for gcc-help@gcc.gnu.org; Tue, 26 Oct 2021 19:23:50 -0400 Message-ID: <1635290628.10041.1.camel@gnu.org> Subject: which gcc options can control layout of bit fields From: Andrew Makhorin To: gcc-help Date: Wed, 27 Oct 2021 02:23:48 +0300 Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6-1+deb9u2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.2 required=5.0 tests=BAYES_50, BODY_8BITS, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Oct 2021 23:23:52 -0000 Hi, Could anyone tell me which gcc options can control layout of bit fields? The problem I encountered is that gcc for Cygwin doesn't follow System V ABI for i386. Namely, ABI says:     A bit-field must entirely reside in a storage unit appropriate for     its declared type. Thus a bit-field never crosses its unit boundary. But in the code generated by gcc under Cygwin bit fields are allocated contiguously and may cross the unit boundary. On the other hand, gcc under Linux follows the ABI conventions. Example: struct { int a; char b; int c:14, d:14; int e; }    s = {0xAAAAAAAA, 0xBB, 0xCCC, 0xDDD, 0xEEEEEEEE}; static int *p = (int *)&s; int main(void) {       printf("0x%08X 0x%08X 0x%08X 0x%08X\n", p[0], p[1], p[2], p[3]);       return 0; } Under Cygwin s.d is splitted between p[1] and p[2]: 0xAAAAAAAA 0x774CCCBB 0x00000003 0xEEEEEEEE Under Linux all is okay: 0xAAAAAAAA 0x000CCCBB 0x00000DDD 0xEEEEEEEE Thank you, Andrew Makhorin