Opened 14 months ago

#172 new defect

Anonymous struct can conflict across translation unit

Reported by: Thierry Delisle Owned by:
Priority: major Component: cfa-cc
Version: 1.0 Keywords: mangling, backwards-compatibility


Given a header fred.hfa with the following code:

typedef struct { /*...*/ } my_struct_t;

void foo( my_struct_t * );

This will create a struct of name anonymous[N] where [N] is replaced by a simple counter.

Now if and include the file as follows:

--- ---
#include "fred.hfa"

/* ... use foo() ... */

--- ---
typedef struct { int i; } my_int_t;
#include "fred.hfa"

/* ... use foo() ... */

In these 2 files, since the number of structs anonymous struct differs, foo will mangle differently.

This means that it may be impossible to link the 2 files together.

Note: linux makes heavy use of typedef struct which means this can break code easily

Change History (0)

Note: See TracTickets for help on using tickets.