From owner-freebsd-current@FreeBSD.ORG Tue Jan 27 22:59:19 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 3CE001065939 for ; Tue, 27 Jan 2009 22:59:19 +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 97A1A8FC1C for ; Tue, 27 Jan 2009 22:59:18 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: (qmail invoked by alias); 27 Jan 2009 22:59:16 -0000 Received: from p54A3E59D.dip.t-dialin.net (EHLO tron.homeunix.org) [84.163.229.157] by mail.gmx.net (mp067) with SMTP; 27 Jan 2009 23:59:16 +0100 X-Authenticated: #1673122 X-Provags-ID: V01U2FsdGVkX1/2mSM1cyf2eXJB5jZA9z8RexqcmM2BxDAb5uCXtd AWmMdOEcxKaf/I Message-ID: <497F91C3.7040502@gmx.de> Date: Tue, 27 Jan 2009 23:59:15 +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> In-Reply-To: <20090127132102.GA21574@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.6 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 22:59:23 -0000 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. > Sources including both ipfw2.h and /usr/include/netinet/ip_fw2.h > However if the duplication occurs in two non-system files, the > compiler produces an error for a duplicate typedef. > > Now i wonder, is there any compiler option to turn off the check > for duplicate typedefs also for non-system headers ? No. C forbids multiple typedefs of with the same name, even if they are typedefs for the same type. (Side note: C++ allows this.) > BTW the behaviour with duplicate typedefs is curious, > you can try this for yourself with a simple example > involving e.g. /usr/include/sha.h : make a copy of the file > in userspace, and then you can try the following (SHA_CTX > is typedef'ed in sha.h > > --- ok --- > typedef struct SHAstate_st SHA_CTX; > #include > > --- ok --- > #include > typedef struct SHAstate_st SHA_CTX; > > --- error --- > #include "sha.h" > typedef struct SHAstate_st SHA_CTX; > > --- error --- > typedef struct SHAstate_st SHA_CTX; > #include "sha.h" > > --- ok (this is surprising to me) -- > typedef struct SHAstate_st SHA_CTX; > #include > typedef struct SHAstate_st SHA_CTX; > > As you note, it looks like a typedef in a system header > removes the error message for duplicates both before and after. This is a misfeature in GCC and violates the C standard. Also it seems that this misfeature has a bug, too, because it does not only affect system headers, but the effects radiate into normal code, too. Regards Christoph