Re: types, variable names and fields



On Thu, 26 Jun 2008 16:52:06 +0200, Joachim Schmitz wrote:
SRoubtsov@xxxxxxxxx wrote:
Dear all,

Do you know whether ANSI C (or some other dialects) support the
following:
* a variable name coincides with a type name,
* a structure/union field name coincides with a type name
in the same file (.c + all relevant .h's)?

e.g.

typedef int m;

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

char *m
typedefs and variable identifiers (and struct/union tags) life in
different name spaces, so they can coexist if they have the same name.

No, assuming the same scope, no two typedefs, objects, or functions may
have identical names. Not in standard C, and not in any dialect that I'm
aware of. It's not possible to parse C if you can't determine what
declaration an identifier refers to. Given the above, if it were valid, it
would not be possible for a compiler to determine whether (m)+0 is a cast
of +0 to type m, or adds 0 to object m.

For structure/union tags ("a" in the above) and members, it's indeed
allowed to use the same name as for an existing object or typedef. There's
no problem with "char m;" in the above.
.