Declarations hiding type names

Y

ymuntyan

Hey,

Is the following code valid:

typedef int A;
void func (void)
{
A A;
}

It looks right to me, the second "A" is a type name from
the outer scope when it's seen, so it's not hidden by the
third "A", and so that's a declaration

outer-type-A in-func-variable-A;

What makes me doubt about it is that all yacc-like
parsers I looked at will parse that line inside func() as

outer-type-A outer-type-A
 
Y

ymuntyan

On Fri, 14 Mar 2008 18:27:55 -0700$B!$(Bymuntyan wrote$B!'(B






True.

A typedef name is also an identifier, and it "shares the same name space
as other identifiers declared in ordinary declarators."

Your in-func-variable-A just shadows the global-typedef-name-A.




You should ask this question in a yacc newsgroup instead.

Well, I figured it out. The problem was over-optimistic
people who claim that simple if-typedef-then-typename
trick will solve the typedef-name vs identifier issue.
And gcc's yacc grammar indeed has a load of stuff to
solve this issue.
Not sure why I would ask a question about C grammar in
a yacc newsgroup though ;)

Yevgen
 
W

WANG Cong

On Fri, 14 Mar 2008 18:27:55 -0700,ymuntyan wrote:
Hey,

Is the following code valid:

typedef int A;
void func (void)
{
A A;
}

It looks right to me, the second "A" is a type name from the outer scope
when it's seen, so it's not hidden by the third "A", and so that's a
declaration

outer-type-A in-func-variable-A;


True.

A typedef name is also an identifier, and it "shares the same name space
as other identifiers declared in ordinary declarators."

Your in-func-variable-A just shadows the global-typedef-name-A.
What makes me doubt about it is that all yacc-like parsers I looked at
will parse that line inside func() as

outer-type-A outer-type-A

You should ask this question in a yacc newsgroup instead.
 
W

WANG Cong

On Fri, 14 Mar 2008 19:25:50 -0700,ymuntyan wrote:
Well, I figured it out. The problem was over-optimistic people who claim
that simple if-typedef-then-typename trick will solve the typedef-name
vs identifier issue. And gcc's yacc grammar indeed has a load of stuff
to solve this issue.
Not sure why I would ask a question about C grammar in a yacc newsgroup
though ;)

What you doubt about is your tool, yacc, not the C language itself. You
mentioned you know the language syntax is correct. And here only discuss
the standard C language, neither its extensions nor any implementions.

I think gnu.gcc.help will be much more appropriate to discuss your
problem, or any other yacc groups which I don't know.
 
K

Kenny McCormack

WANG Cong <[email protected]> tediously scribed (as if the
point hadn't been made 50,000,000 times over the past 15 years):
....
What you doubt about is your tool, yacc, not the C language itself. You
mentioned you know the language syntax is correct. And here only discuss
the standard C language, neither its extensions nor any implementions.

Tedious.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top