From owner-freebsd-current@FreeBSD.ORG Wed Jan 28 11:47:47 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 A54531065687 for ; Wed, 28 Jan 2009 11:47:47 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.freebsd.org (Postfix) with SMTP id E8DD68FC20 for ; Wed, 28 Jan 2009 11:47:46 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: (qmail invoked by alias); 28 Jan 2009 11:47:45 -0000 Received: from p54A3E68D.dip.t-dialin.net (EHLO tron.homeunix.org) [84.163.230.141] by mail.gmx.net (mp005) with SMTP; 28 Jan 2009 12:47:45 +0100 X-Authenticated: #1673122 X-Provags-ID: V01U2FsdGVkX1/jkOde9MvjcPdHrWssBVFAoLtOza4UQQOdimvLI6 8HAmFnc0OqSijR Message-ID: <498045E0.3050405@gmx.de> Date: Wed, 28 Jan 2009 12:47:44 +0100 From: Christoph Mallon User-Agent: Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: Luigi Rizzo References: <20090127132102.GA21574@onelab2.iet.unipi.it> <497F91C3.7040502@gmx.de> <20090127232103.GA40501@onelab2.iet.unipi.it> In-Reply-To: <20090127232103.GA40501@onelab2.iet.unipi.it> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-FuHaFi: 0.59 Cc: current@freebsd.org Subject: Re: duplicate typedefs and system headers ? 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: Wed, 28 Jan 2009 11:47:48 -0000 Luigi Rizzo schrieb: > On Tue, Jan 27, 2009 at 11:59:15PM +0100, Christoph Mallon wrote: >> Luigi Rizzo schrieb: >>> In a recent commit tp sbin/ipfw, in an attempt to avoid >>> a large set of header deependencies, i put a 'forward typedef' >>> declaration in a common header, duplicating something that is in a >>> system header: >>> >>> ipfw2.h: typedef struct _ipfw_insn ipfw_insn; >>> >>> netiinet/ip_fw2.h >>> typedef struct _ipfw_insn { /* template for instructions */ >>> ... >>> } ipfw_insn; >> This just begs to break, if somebody decides to change the name of the >> underlying type of the typedef. > > Fortunately this is almost impossible -- the system header is > basically frozend and if I could change it I would remove the > typedef in the first place. > > I am more worried of compatibility with different compiler. > > A workaround that seems to work is putting forward declarations > just for "struct _ipfw_insn" and use it (instead of the typedef > name) in the place that does not include netiinet/ip_fw2.h > > Would this be better/more compliant with standards -- i.e., > is the following code correct ? gcc seems to have no objections. > > struct foo; > int a(struct foo *); > typedef struct foo bar; > int a(bar *x) { ... } What is the problem with just including the correct header? This would be The Right Thing(tm). Everything else is just an ugly hack.