[systemd-devel] [PATCH] core: Remove unnecessary typedef

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Apr 17 09:42:51 PDT 2013


On 17/04/13 17:25, Kay Sievers wrote:
> On Wed, Apr 17, 2013 at 6:08 PM, Henrik Grindal Bakken <hgb at ifi.uio.no> wrote:
>> ExecContext isn't used in this header file, and everything seems to
>> build just fine without this typedef.  The typedef doesn't really belong
>> here, and at least my gcc-4.4.6 gives an error on type redefined.
> 
> Weird, this type of forward-declaration is a common pattern.

We had this bug in telepathy-glib too:

"typedef struct Xyz Xyz;", seen once per translation unit, is fine.

"typedef struct Xyz Xyz; typedef struct Xyz Xyz;" was an error in C89
and C99, but is allowed in C11.

The portable thing to do is to have the typedef in exactly one header
file (which doesn't necessarily have to be the same one that declares
the contents of a "struct Xyz"), and have everything else that mentions
Xyz include that header.

    S


More information about the systemd-devel mailing list