logoalt Hacker News

nxobjecttoday at 5:45 AM1 replyview on HN

If stevefan1999's referring to a nasty frontend issue, it might be due to the fact that a name introduced by a typedef and an identical identifier can mingle in the same scope, which makes parsing pretty nasty – e.g. (example from source at end):

  typedef int AA;
  
  void foo()
  {
    AA AA;            /\* OK - define variable AA of type AA */
    int BB = AA * 2;  /\* OK - AA is just a variable name here \*/
  }

  void bar()
  {
    int aa = sizeof(AA), AA, bb = sizeof(AA);
  }

https://eli.thegreenplace.net/2011/05/02/the-context-sensiti...

I don't know off the top of my head whether there's a parser framework that makes this parse "straightforward" to express.


Replies

delusionaltoday at 6:31 AM

In your example bar is actually trivial, since both the type AA and the variable AA are ints both aa and bb ends up as 4 no matter how you parse it. AA has to be typedef'd to something other than int.