Re: types, variable names and fields
- From: Harald van Dijk <truedfx@xxxxxxxxx>
- Date: Thu, 26 Jun 2008 18:14:48 +0200
On Thu, 26 Jun 2008 16:52:06 +0200, Joachim Schmitz wrote:
SRoubtsov@xxxxxxxxx wrote:
Dear all,typedefs and variable identifiers (and struct/union tags) life in
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
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.
.
- Follow-Ups:
- Re: types, variable names and fields
- From: Joachim Schmitz
- Re: types, variable names and fields
- References:
- types, variable names and fields
- From: SRoubtsov
- Re: types, variable names and fields
- From: Joachim Schmitz
- types, variable names and fields
- Prev by Date: Re: How to learn C ?
- Next by Date: Re: Getting the file name from a FILE *
- Previous by thread: Re: types, variable names and fields
- Next by thread: Re: types, variable names and fields
- Index(es):