logoalt Hacker News

Show HN: Cdecl-dump - represent C declarations visually

28 pointsby bluetomcattoday at 12:26 AM10 commentsview on HN

A small tool that parses C declarations and outputs a simple visual representation at each stage, as it encounters arrays, pointers or functions.

The program uses a table-driven lexer and a hand-written, shift-reduce parser. No external dependencies apart from the standard library.


Comments

coherentponytoday at 1:49 AM

I don’t understand what the visualisation screenshot in the README is trying to communicate to me.

show 1 reply
pcfwiktoday at 1:56 AM

Since this is about C declarations: for anyone who (like me) had the misfortune of learning the so-called "spiral rule" in college rather than being taught how declarations in C work, below are some links that explain the "declaration follows use" idea that (AFAIK) is the true philosophy behind C declaration syntax (and significantly easier to remember/read/write).

TL;DR: you declare a variable in C _in exactly the same way you would use it:_ if you know how to use a variable, then you know how to read and write a declaration for it.

https://eigenstate.org/notes/c-decl https://news.ycombinator.com/item?id=12775966

show 2 replies