From owner-freebsd-current@FreeBSD.ORG Mon Nov 30 01:11:14 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 3B7311065676 for ; Mon, 30 Nov 2009 01:11:14 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outM.internet-mail-service.net (outm.internet-mail-service.net [216.240.47.236]) by mx1.freebsd.org (Postfix) with ESMTP id 225868FC19 for ; Mon, 30 Nov 2009 01:11:13 +0000 (UTC) Received: from idiom.com (mx0.idiom.com [216.240.32.160]) by out.internet-mail-service.net (Postfix) with ESMTP id A1C9D39EC5; Sun, 29 Nov 2009 17:11:13 -0800 (PST) X-Client-Authorized: MaGic Cook1e X-Client-Authorized: MaGic Cook1e Received: from julian-mac.elischer.org (h-67-100-89-137.snfccasy.static.covad.net [67.100.89.137]) by idiom.com (Postfix) with ESMTP id 5089C2D601A; Sun, 29 Nov 2009 17:11:13 -0800 (PST) Message-ID: <4B131BB5.7010106@elischer.org> Date: Sun, 29 Nov 2009 17:11:17 -0800 From: Julian Elischer User-Agent: Thunderbird 2.0.0.23 (Macintosh/20090812) MIME-Version: 1.0 To: Luigi Rizzo References: <20091130011643.GA29020@onelab2.iet.unipi.it> In-Reply-To: <20091130011643.GA29020@onelab2.iet.unipi.it> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: current@freebsd.org Subject: Re: 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:11:14 -0000 Luigi Rizzo wrote: > 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 think from memory enums are only defined to be ints and an 8 bit enum is a gcc extension. > > 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 > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"