unique namespace for typedefs, struct names, struct tags?
Root Boy Jim
rbj at icst-cmr
Fri Mar 14 03:38:20 AEST 1986
I recently ran into a problem with a C compiler with the following
typedef:
typedef struct foo {
struct foo *next;
int foo;
} foo;
It didn't like the multiple uses of "foo". Since I am porting
someone else's large program and not writing one from scratch,
the solution of "don't do it that way" doesn't work for me.
You are within your rights. But don't try saying: `foo foo;' later on.
Typedefs share the same name space as ordinary identifiers. Struxure
tags are a completely different namespace. Each struxure has its own
separate name space which is its own little universe, separate from
other struxures and the global name space.
Be sure you haven't used foo as a variable elsewhere, altho scope
rules allow redefining within blox. My 4.2 compiler handles the
above fragment okay. I would expect other serious ones to as well.
Is there any statement in the ANSI proposed standard regarding this
name space issue? I'd like to be able to coax my compiler vendor
to fix it with a reasonable argument like conformance rather than
saying "well, it works right with the 4.2 compiler."
Tell him to read K&R and get the ANSI standard draft.
Thanks in advance.
Alan Crosswell
Columbia University
More information about the Comp.lang.c
mailing list