Re: types, variable names and fields



SRoubtsov@xxxxxxxxx wrote:

Do you know whether ANSI C (or some other dialects) support the following:

It's ISO C these days, BTW.

* a variable name coincides with a type name,

No, that's not allowed.

* a structure/union field name coincides with a type name
in the same file (.c + all relevant .h's)?

That is allowed. It's also allowed for the struct type itself to have
the same name as another type or object, because the struct keyword
disambiguates between them.

typedef int m;

typedef struct a {
int i;
char m;
} b;

char *m

The typedef and the char * clash. The char field does not clash with
either of those. And if you'd called it struct m, that would not have
clashed with any of the others, either.

Richard
.



Relevant Pages