duplicate typedefs and system headers ?

From: Luigi Rizzo <rizzo_at_iet.unipi.it>
Date: Tue, 27 Jan 2009 14:21:02 +0100
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;

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 ?

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 <sha.h>

--- ok ---
	#include <sha.h>
	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 <sha.h>
	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.

	cheers
	luigi
Received on Tue Jan 27 2009 - 12:15:31 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:41 UTC