Skip to content

C allows redefinition of a typedef #9

@kevinsneel

Description

@kevinsneel

It is not actually true that 'a * b; ' is illegal if both are types. It is actually legal to define, e.g., a structure member as the same name as an existing typedef name. See, e.g., C99 6.7.7 example 3:

EXAMPLE 3 The following obscure constructions
typedef signed int t;
typedef int plain;
struct tag {
unsigned t:4;
const t:5;
plain r:5;
};
declare a typedef name t with type signed int,atypedef name plain with type int, and a structure with three bit-field members, one named t that contains values in the range [0, 15], ...

As far as I can see. nearly all redeclarations in a different namespace or inner scope are allowed. The only exception I see is in 6.9.1 paragraph 6: "An identifier declared as a typedef name shall not be redeclared as a parameter."

Unfortunately, it seems breaking that last rule is not uncommon. So maybe if we could allow that to be a warning, it would be very helpful.

Thanks for cast!
Kevin

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions