Declarations hiding type names

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ymuntyan@gmail.com

    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

  • WANG Cong

    #2
    Re: Declarations hiding type names

    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.

    Comment

    • ymuntyan@gmail.com

      #3
      Re: Declarations hiding type names

      On Mar 14, 10:45 pm, WANG Cong <xiyou.wangc... @gmail.comwrote :
      On Fri, 14 Mar 2008 18:27:55 -0700$B!$(Bymu ntyan 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

      Comment

      • WANG Cong

        #4
        Re: Declarations hiding type names

        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.

        Comment

        • Kenny McCormack

          #5
          Re: Declarations hiding type names

          In article <frg2lm$d8c$1@n ews.cn99.com>,
          WANG Cong <xiyou.wangcong @gmail.comtedio usly 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.

          Comment

          Working...