473,398 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Declarations hiding type names

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

Mar 15 '08 #1
4 1395
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.
--
Hi, I'm a .signature virus, please copy/paste me to help me spread
all over the world.
Mar 15 '08 #2
On Mar 14, 10:45 pm, WANG Cong <xiyou.wangc...@gmail.comwrote:
On Fri, 14 Mar 2008 18:27:55 -0700$B!$(Bymuntyan wrote$B!'(B
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.
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
Mar 15 '08 #3
On Fri, 14 Mar 2008 19:25:50 -0700,ymuntyan wrote:
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.

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.

--
Hi, I'm a .signature virus, please copy/paste me to help me spread
all over the world.
Mar 15 '08 #4
In article <fr**********@news.cn99.com>,
WANG Cong <xi************@gmail.comtediously 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.

Mar 16 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Michael Tobis | last post by:
Summary of my understanding of a recent interesting thread: General usage has "declaration" meaning "statement which does not generate executable bytecode but merely affects the compiler". My...
0
by: Rikard Land | last post by:
I try to model a data definition language in XML. It can be seen as C without any executable statements other than variable assignments. I want to allow for: (1) type declarations ("structs" in...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
12
by: Alex Hunsley | last post by:
There's no really specific questions in this post, but I'm looking for people's thought on the issues within... The two main versions I've encountered for data pseudo-hiding (encapsulation) in...
20
by: Elliot Marks | last post by:
If a struct or its members are passed to a function, must it be declared globally? #include <stdio.h> struct mystruct{ int a; int b; }; int structfunc(struct mystruct foo);
3
by: Till Crueger | last post by:
Hi, I am trying to implement a tree in C and I have the folowing code: struct inner { struct node *left; struct node *right; }; struct leaf {
3
by: steve | last post by:
Hi all, I want to be able to hirearchally define event delegate (declarations) WITHIN interfaces. Unfortunatelly C# 1 doesn't appear to support it. How does the following look as a...
26
by: samjnaa | last post by:
Hello. Please tell me whether this feature request is sane (and not done before) for python so it can be posted to the python-dev mailing list. I should say first that I am not a professional...
7
by: aspineux | last post by:
Hi I read the PEP 3117 about the new "Postfix type declarations" in Python3000. THIS PEP as been REJECTED ! But ... The notation in the PEP is very ugly ! This make python code more...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.