From owner-freebsd-current@FreeBSD.ORG Mon Nov 30 01:08:36 2009 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B6BDF106568B for ; Mon, 30 Nov 2009 01:08:36 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id 7D47C8FC17 for ; Mon, 30 Nov 2009 01:08:36 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 4B7ED730DA; Mon, 30 Nov 2009 02:16:43 +0100 (CET) Date: Mon, 30 Nov 2009 02:16:43 +0100 From: Luigi Rizzo To: current@freebsd.org Message-ID: <20091130011643.GA29020@onelab2.iet.unipi.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i Cc: Subject: poor struct definition in ipfw (bitfield with enum base type) ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Nov 2009 01:08:36 -0000 While trying to compile ipfw (userland) with tcc, i hit an issue on the following struct in ip_fw.h (I think I wrote it): typedef struct _ipfw_insn { /* template for instructions */ enum ipfw_opcodes opcode:8; u_int8_t len; /* number of 32-bit words */ u_int16_t arg1; } ipfw_insn; gcc correctly packs the structure in 4 bytes, however tcc fails to realize that the enum fits in 8 bits, and uses the base type (int, which is 32 bit) which results in the structure using 8 bytes. You can imagine the results. I wonder if the difference is a bug in 'tcc' or it is one of those things that are 'implementation-defined' by the C99 standard (googling around seems to suggest the latter). grepping through the entire /usr/src shows only one instance of the above construct (a bitfield using an enum as base type). To be safe, I'd be inclined to change 'opcode' to uint8_t, which is non ambiguous and generates the same code on gcc and tcc cheers luigi