From owner-freebsd-current@FreeBSD.ORG Tue Jan 27 23:15:32 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 4EEEA1065973 for ; Tue, 27 Jan 2009 23:15:32 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.9.129]) by mx1.freebsd.org (Postfix) with ESMTP id 13EE18FC17 for ; Tue, 27 Jan 2009 23:15:31 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 4159B73098; Wed, 28 Jan 2009 00:21:03 +0100 (CET) Date: Wed, 28 Jan 2009 00:21:03 +0100 From: Luigi Rizzo To: Christoph Mallon Message-ID: <20090127232103.GA40501@onelab2.iet.unipi.it> References: <20090127132102.GA21574@onelab2.iet.unipi.it> <497F91C3.7040502@gmx.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <497F91C3.7040502@gmx.de> User-Agent: Mutt/1.4.2.3i 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: Tue, 27 Jan 2009 23:15:32 -0000 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) { ... } cheers luigi